[Tutor] I need to learn more about sorting!

Kent Johnson kent37 at tds.net
Tue Jun 24 12:18:28 CEST 2008


On Tue, Jun 24, 2008 at 1:15 AM, Dick Moores <rdm at rcblue.com> wrote:
> At 07:15 PM 6/23/2008, Kent Johnson wrote:

>> You should learn how to use list comprehensions:
>> alist_tup_elements_reversed.append = [ (x[1], x[0]) for x in alist ]
>
> Now, that's why I don't use them. They don't make sense, I thought. But
> that's a typo, or a paste-o, right? You meant
> alist_tup_elements_reversed = [ (x[1], x[0]) for x in alist ], which works.

Yes, a paste-o.

I have a short introduction to list comprehensions here:
http://personalpages.tds.net/~kent37/kk/00003.html

Although the syntax takes a little getting used to, I think it is just
because it is an unusual concept. I find list comps easier to write
and understand than the equivalent loop.

Kent


More information about the Tutor mailing list