Sorting things into bins
Jason Orendorff
jason at jorendorff.com
Wed Dec 12 20:00:28 EST 2001
More information about the Python-list mailing list
Wed Dec 12 20:00:28 EST 2001
- Previous message (by thread): Sorting things into bins
- Next message (by thread): Sorting things into bins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Is there a quick and simple way to sort a set of values (strings in this
> case) into a set of bins, based on a subset of the characters in the
> string?
mylist = ['0101', '0102', '0103', '0201', '0202', '0203']
mybins = {}
for s in mylist:
bin = s[-2:]
mybins.setdefault(bin, []).append(s)
print mybins
--
Jason Orendorff http://www.jorendorff.com/
- Previous message (by thread): Sorting things into bins
- Next message (by thread): Sorting things into bins
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list