Sorting things into bins
Sean 'Shaleh' Perry
shalehperry at attbi.com
Thu Dec 13 11:58:06 EST 2001
On 13-Dec-2001 Sue Giller wrote:
> Jason,
>
> While I was hoping to not have to iterate thru the list, this recipe is
> fine for my needs. I also learned about the .setdefault method -
> thanks!
>
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
More information about the Python-list
mailing list