[Tutor] string to list
kent37 at tds.net
Thu Feb 11 14:16:42 CET 2010
On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> 2) given that you have lists as items in the 'data' list, it's enough to
> call sort() once, as the comparison of lists is defined as the comparison
> of each item to the corresponding item of the other list. If you want to
> sort based on the second item before the first item, it's best to exchange
> both items before sorting and swap them back afterwards.
No, that is the old decorate-sort-undecorate idiom which has been
replaced by the key= parameter to sort.
data.sort(key=operator.itemgetter(1)) is the best way to sort on the
More information about the Tutor