grab dict keys/values without iterating ?!

Tim Chase python.list at tim.thechases.com
Wed Dec 11 09:30:51 EST 2013


On 2013-12-11 13:44, Steven D'Aprano wrote:
> If necessary, I would consider having 26 dicts, one for each
> initial letter:
> 
> data = {}
> for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
>     data[c] = {}
> 
> then store keys in the particular dict. That way, if I wanted keys 
> starting with Aa, I would only search the A dict, not the B dict, C
> dict, etc.

That's what the convoluted code does that I put at the end of my
previous post in this thread, only to the Nth degree (the outermost
dict has the first letter which links to a dictionary of the 2nd
level/letter, to the 3rd level/letter, etc).

-tkc



More information about the Python-list mailing list