Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69549

Retrieve item deep in dict tree?

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 <roy@panix.com>
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 <roy@panix.com>
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 <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8818.1396461529.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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.

---
Roy Smith
roy@panix.com

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Retrieve item deep in dict tree? Roy Smith <roy@panix.com> - 2014-04-02 13:58 -0400
  Re: Retrieve item deep in dict tree? John Gordon <gordon@panix.com> - 2014-04-02 18:03 +0000
  Re: Retrieve item deep in dict tree? Steven D'Aprano <steve@pearwood.info> - 2014-04-02 20:18 +0000
    Re: Retrieve item deep in dict tree? Ethan Furman <ethan@stoneleaf.us> - 2014-04-02 13:25 -0700
  Re: Retrieve item deep in dict tree? Rustom Mody <rustompmody@gmail.com> - 2014-04-02 19:41 -0700
    Re: Retrieve item deep in dict tree? Rustom Mody <rustompmody@gmail.com> - 2014-04-02 21:15 -0700
      Re: Retrieve item deep in dict tree? Steven D'Aprano <steve@pearwood.info> - 2014-04-03 05:29 +0000
      Re: Retrieve item deep in dict tree? Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-03 01:00 -0600

csiph-web