Re: dictionary idiom needed

2008-12-11 Thread Brandon
> >>> d = defaultdict(lambda: defaultdict(int)) > > Arnaud Ah... so that's what lambdas are for. Many thanks! Brandon -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary idiom needed

2008-12-11 Thread Arnaud Delobelle
Brandon writes: > Thanks bear - > > Some outside advice has me looking at nested dictionaries. But I am > still bogged down because I've not created one before and all examples > I can find are simple ones where they are created manually, not with > loops. Maybe a further example: > > data: >

Re: dictionary idiom needed

2008-12-11 Thread Brandon
> Smells like homework without a particular application. @Scott: Even if that were the case :) I'd still like to figure out how to create nested dictionaries! Brandon -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary idiom needed

2008-12-11 Thread Brandon
Thanks bear - Some outside advice has me looking at nested dictionaries. But I am still bogged down because I've not created one before and all examples I can find are simple ones where they are created manually, not with loops. Maybe a further example: data: POS1POS2 POS3 ['word1','tag

Re: dictionary idiom needed

2008-12-11 Thread Scott David Daniels
Brandon wrote: I have a series of lists in format ['word', 'tagA', 'tagB']. I have converted this to a few dicts, such as one in which keys are tuples of ('word', 'tagB'), and the values are the number of times that key was found. Smells like homework without a particular application. --

Re: dictionary idiom needed

2008-12-11 Thread bearophileHUGS
bearophile: > you can do with a dict > that has the tuple ('word', 'tagB') as key, and as value has a > collections.defaultdict(int) that maps 'tagB' to its count. Where's 'tagA'? Probably I haven't understood your problem well enough. I need a better example of your data and what you need... Sor

Re: dictionary idiom needed

2008-12-11 Thread bearophileHUGS
Brandon: > I need an dictionary idiom whereby I can find all instances of > a given 'word' with any 'tagB', and then subdivide into all instances > of a given 'tagB'.  In both cases I would want the value as a count of > all instances found. If I have understood you well enough, I think you can do

dictionary idiom needed

2008-12-11 Thread Brandon
Hi all, I have a series of lists in format ['word', 'tagA', 'tagB']. I have converted this to a few dicts, such as one in which keys are tuples of ('word', 'tagB'), and the values are the number of times that key was found. I need an dictionary idiom whereby I can find all instances of a given '