[Tutor] Bundle help!

Alan Gauld alan.gauld at btinternet.com
Mon Jul 9 09:26:32 CEST 2007


"Sara Johnson" <sarliz73 at yahoo.com> 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 




More information about the Tutor mailing list