dictionary issue (and maybe PEP ... depending on the answer)
Ian Bicking
ianb at colorstudy.com
Wed Jun 4 00:04:22 EDT 2003
On Mon, 2003-06-02 at 00:45, dsavitsk wrote:
> never mind, for now, that there are proably better ways to do what the
> dict obviously does. anyhow, I get a list of the months by doing this
>
> >>> [_months[i] for i in _months.keys()]
Now what I'd like is:
[m for m, i in _months.items() sortby i]
Such an addition to list comprehension would make everyone who doesn't
like the sort method happy, plus it's just a much better way to express
sorting, so you could do things like:
[p for p in people sortby p.lastname, p.firstname]
instead of:
l = people[:]
l.sort(lambda a, b: cmp((a.lastname, a.firstname),
(b.lastname, b.firstname))
More information about the Python-list
mailing list