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


Groups > comp.lang.python > #26872

Re: dictionary into desired variable....

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'suppose': 0.07; 'python': 0.09; 'dict': 0.09; 'subject:into': 0.09; 'aug': 0.13; 'sat,': 0.15; 'dictionary,': 0.16; 'dictionary.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'idx': 0.16; 'mapping,': 0.16; 'mean,': 0.16; 'received:209.85.161.174': 0.16; 'unordered': 0.16; 'variable.': 0.16; 'wrote:': 0.17; 'keys': 0.22; 'this:': 0.23; 'header:In- Reply-To:1': 0.25; 'looks': 0.26; 'am,': 0.27; 'question': 0.27; 'start,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'represent': 0.28; 'dictionary': 0.29; 'points': 0.29; "skip:' 10": 0.30; 'certain': 0.33; '11,': 0.33; 'clarify': 0.33; 'values.': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'list,': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'your': 0.60; 'subject:....': 0.65; 'receive': 0.71
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=k/K+LT2x5icvWoZXZQFq6IUrKz5rkdC/SsDyzD5VF3c=; b=TTQaBKt7+j+wS/d1mBO6vbnGC3ZPlSoo2eBaeKgLNg7vfzAnEhd3FQ0DGH7xF5VVka 5tURthgZZ65k8t+toVqsJDCSSC0fBz82Cqd3BIuWHR2lYuJQmYmzjQ0LPSAtEojpaTG3 EJVJ4fjFg8BHO/4Bljh9KO3gYHh5fl3AFME/8KlNl3h93oNRAp0Rw1yt7Ix8Y6iG5vsg 9ZIED16CLwkPGTEBwlkeILGclKK0Iw7xp3V9ZlmQmVLUIXEvtuppnSjsqT70YdGH8nbE 6WCXvRTziC0vdfwjUelW4UlVoKNYkatVnpxe8VgOFmkSTUCcKyQn/fQPpRP2iaLl5pNu ULwg==
MIME-Version 1.0
In-Reply-To <50251477.7010507@googlemail.com>
References <50251477.7010507@googlemail.com>
Date Sat, 11 Aug 2012 00:31:07 +1000
Subject Re: dictionary into desired variable....
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3162.1344609071.4697.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344609071 news.xs4all.nl 6975 [2001:888:2000:d::a6]:36581
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26872

Show key headers only | View raw


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

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


Thread

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

csiph-web