Sorting things into bins
Andrae Muys
amuys at shortech.com.au
Thu Dec 13 21:47:25 EST 2001
More information about the Python-list mailing list
Thu Dec 13 21:47:25 EST 2001
- Previous message (by thread): Sorting things into bins
- Next message (by thread): Where can you find the Python ODBC modual
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Sean 'Shaleh' Perry" <shalehperry at attbi.com> wrote in message news:<mailman.1008262758.25790.python-list at python.org>... > def sorter(bins, item): > bin = item[-2:] > bins.setdefault(bin, []).append(item) > > mylist = ['0102', '0302', '1242'] > mybins = {} > map(lambda x: sorter(mybins, x), mylist) > print mybins ... and just because I think List Comprehensions are really cool..... >>> mylist = ['0101', '0102', '0103', '0201', '0202', '0203'] >>> [bins.setdefault(s[-2:], []).append(s) for bins in [{}] for s in mylist] [None, None, None, None, None, None] >>> print bins {'02': ['0102', '0202'], '03': ['0103', '0203'], '01': ['0101', '0201']} Andrae Muys
- Previous message (by thread): Sorting things into bins
- Next message (by thread): Where can you find the Python ODBC modual
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list