I brought this up with Kent a little while ago...
>>>If you have a list of pairs of (name, percentage) then you should be
>>>able to sort it directly with the sort() method of the list. For
>>>example:
>>>In [3]: data = [ ('Kent', 50), ('Sara', 80), ('Fred', 20) ]
>>>In [4]: data.sort()
>>>In [5]: data
>>>Out[5]: [('Fred', 20), ('Kent', 50), ('Sara', 80)]
>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?
I guess in this case it would be....
('Fred', 20), ('Joe', 50), ('Kent', 80), ('Sara', 90)
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)]
How would I do that so I wind up with both lists? I have two lists now, but
if I try and reorder them they just reverse in alphabetical order without
affecting the second value (the number).
Thanks!
---------------------------------
Boardwalk for $500? In 2007? Ha!
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor