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


Groups > comp.lang.python > #26873

Re: dictionary into desired variable....

References <50251477.7010507@googlemail.com>
From Zero Piraeus <schesis@gmail.com>
Date 2012-08-10 10:36 -0400
Subject Re: dictionary into desired variable....
Newsgroups comp.lang.python
Message-ID <mailman.3163.1344609427.4697.python-list@python.org> (permalink)

Show all headers | View raw


:

> suppose you have a dictionary that looks like this:
>
> x = [1,3,6,1,1] which should represent a certain other variable.

That's a list, not a dict.

> in reality it would represent:
>
> y[1][3][6][1][1]
>
> Now, how do I write a python routine, that points in this dictionary,
> where I should receive or set other values.

>>> x = [1, 3, 6, 1, 1]
>>> y = [0, [0, 1, 2, [0, 1, 2, 3, 4, 5, [0, [0, 'bingo!']]]]]
>>> def drill(tree, path):
...     target = tree
...     for step in path:
...         target = target[step]
...     return target
...
>>> drill(y, x)
'bingo!'
>>>

 -[]z.

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


Thread

Re: dictionary into desired variable.... Zero Piraeus <schesis@gmail.com> - 2012-08-10 10:36 -0400

csiph-web