Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69552
| Date | 2014-04-02 11:15 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Retrieve item deep in dict tree? |
| References | <8E3FFB83-FDCA-4214-A8C6-8681200830DA@panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8820.1396463804.18130.python-list@python.org> (permalink) |
On 04/02/2014 10:58 AM, Roy Smith wrote: > > I have a big hairy data structure which is a tree of nested dicts. I have > a sequence of strings which represents a path through the tree. Different > leaves in the tree will be at different depths (which range from 1 to about > 4 or 5 at most). I want to get the value stored at that path. Thus, if > > keys = ['foo', 'bar', 'baz'] > > I want to retrieve tree['foo']['bar']['baz']. > > Is there some idiomatic, non-cryptic way to write that as a one-liner? > > I'm using Python 2.7. Can you make the top-level tree a custom dict that understands tuple keys should be drilled down? -- ~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Retrieve item deep in dict tree? Ethan Furman <ethan@stoneleaf.us> - 2014-04-02 11:15 -0700
csiph-web