wiki:python/Types/list/sort

count, sort


Python Doc


Listen-Sortierung mit mehreren Faktoren
Sortierung von Listen (Tupel-Listen) anhand einer Liste

Examples

operator/attrgetter

>>> dates = [datetime.datetime(2013, 1, 8), datetime.datetime(2012, 2, 5), datetime.datetime(2011, 3, 9)]
>>> dates
[datetime.datetime(2013, 1, 8, 0, 0),
 datetime.datetime(2012, 2, 5, 0, 0),
 datetime.datetime(2011, 3, 9, 0, 0)]
>>> dates.sort()
[datetime.datetime(2011, 3, 9, 0, 0),
 datetime.datetime(2012, 2, 5, 0, 0),
 datetime.datetime(2013, 1, 8, 0, 0)]
>>> dates.sort(key=operator.attrgetter('day'))
[datetime.datetime(2012, 2, 5, 0, 0),
 datetime.datetime(2013, 1, 8, 0, 0),
 datetime.datetime(2011, 3, 9, 0, 0)]
Last modified 6 years ago Last modified on Oct 15, 2013, 2:25:21 PM