"Sara Johnson" <[EMAIL PROTECTED]> wrote >>Use append() to add more data, then sort again to get it in order: >>>>In [6]: data.append(('Joe', 90)) >>>>In [7]: data.sort() >>>>In [8]: data >>>>Out[8]: [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] > > What happens if I need to sort alphabetical and numerically?
You can supply your own comparison function to the sort routine. You can also just specify the key to sort by for simple cases. > I'm taking the original list and the original values > i.e., ('Fred', 20), ('Joe', 90), ('Kent', 80)... and switching it > so that it reads in both ways... > List 1, [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)] > List 2, ('Fred', 20), ('Joe', 50), ('Kent', 80), ('Sara', 90)] But you lost me here. You seem to be switching the values in the tuples around and its not clear to me by what criteria. HTH -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor