Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'represents': 0.05; 'tree': 0.05; 'nested': 0.07; 'thus,': 0.09; 'python': 0.11; 'stored': 0.12; 'path.': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:24.136': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'subject:item': 0.16; 'to:name:python list': 0.16; 'received:166': 0.19; '---': 0.24; 'received:24': 0.27; "i'm": 0.30; '(which': 0.31; 'keys': 0.31; 'there': 0.35; 'sequence': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'range': 0.61; 'header:Message-Id:1': 0.63; 'different': 0.65; 'smith': 0.68; '2.7.': 0.84; 'email addr:panix.com': 0.84 From: Roy Smith Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Wed, 2 Apr 2014 13:58:16 -0400 Subject: Retrieve item deep in dict tree? To: Python List Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396461529 news.xs4all.nl 2936 [2001:888:2000:d::a6]:45765 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69549 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 =3D ['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. --- Roy Smith roy@panix.com