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


Groups > comp.lang.python > #26872 > unrolled thread

Re: dictionary into desired variable....

Started byChris Angelico <rosuav@gmail.com>
First post2012-08-11 00:31 +1000
Last post2012-08-11 00:31 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: dictionary into desired variable.... Chris Angelico <rosuav@gmail.com> - 2012-08-11 00:31 +1000

#26872 — Re: dictionary into desired variable....

FromChris Angelico <rosuav@gmail.com>
Date2012-08-11 00:31 +1000
SubjectRe: dictionary into desired variable....
Message-ID<mailman.3162.1344609071.4697.python-list@python.org>
On Sat, Aug 11, 2012 at 12:02 AM, Tamer Higazi <th982a@googlemail.com> wrote:
> Hi!
> suppose you have a dictionary that looks like this:
>
> x = [1,3,6,1,1] which should represent a certain other variable.
>
> 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.

For a start, that looks like a list, not a dictionary. A dict in
Python is a mapping, eg a hashtable - an unordered pairing of keys and
values. But this might do what you want:

value = y
for idx in x:
   value = value[idx]

At the end of that, 'value' will be the same as 'y[1][3][6][1][1]'.

If that's not what you mean, you may want to clarify your question some.

Hope that helps!

Chris Angelico

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web