Re: function for counting items in a sequence

2007-04-04 Thread Alex Martelli
Steven Bethard <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > If we had a "turn sequence into bag" function somewhere > > (and it might be worth having it for other reasons): > > > > def bagit(seq): > > import collections > > d = collections.defaultdict(int) > > for x in seq: d

function for counting items in a sequence

2007-04-04 Thread Steven Bethard
Alex Martelli wrote: > If we had a "turn sequence into bag" function somewhere > (and it might be worth having it for other reasons): > > def bagit(seq): > import collections > d = collections.defaultdict(int) > for x in seq: d[x] += 1 > return d I use this function all the time --