Sort comprehensions? (Re: longest sequence)
Manuel Garcia
news at manuelmgarcia.com
Tue Feb 18 20:34:55 EST 2003
On Wed, 19 Feb 2003 13:02:42 +1300, "Greg Ewing (using
news.cis.dfn.de)" <me at privacy.net> wrote:
>Tim Peters wrote:
>
>> The difficulty is that, when comparing
>>
>> (n, seq1)
>> to
>> (n, seq2)
>>
>> the tie on n means seq1 gets compared to seq2 in order to try to break the
>> tie.
>
>
>Maybe list comprehensions should have a sorting clause:
>
> [x for x in stuff sortedby x.key]
So [x for x in stuff sortedby x] would return a sorted copy of
'stuff'?
How would it work with the 'if' cause in a list comprehension?
Not sure how a sorting clause would help with the problem that Tim is
talking about.
Would this work:
[x for x in stuff sortedby (len(x), x)]
to sort by length first?
Manuel
More information about the Python-list
mailing list