[Tutor] Question about sorting a list within a dictionary within a list
Peter Otten
__peter__ at web.de
Mon Aug 1 23:11:11 CEST 2011
Peter Otten wrote:
> Untested:
>
> from operator import attrgetter, itemgetter
> from itertools import imap
>
> firsts = imap(itemgetter(0), conn.get_all_instances())
> reservations = sorted(firsts, key=attrgetter("launch_time"))
>
> This gives you objects rather than the objects' __dict__s.
Oops, I think I missed one level of indirection:
firsts = (r.instances[0] for r in conn.get_all_instances())
reservations = sorted(firsts, key=attrgetter("launch_time"))
More information about the Tutor
mailing list