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


Groups > comp.lang.python > #26877

Re: dictionary into desired variable....

Date 2012-08-10 17:31 +0200
From Tamer Higazi <th982a@googlemail.com>
Subject Re: dictionary into desired variable....
References <50251477.7010507@googlemail.com> <CAPTjJmpB-LiL=+WURP8O6Y=39CYtKuq_zVyVMsWv4qQdmEZFrw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3166.1344612712.4697.python-list@python.org> (permalink)

Show all headers | View raw


Sorry,
I ment of course list....

what I exaclty ment is

that if I assign

value = Number

that I automaticly assign y[1][3][6][1][1] a new number.

more detailled explained:

let us say a would be x = [2,5,4]

y = a[3]

if I change y to []

I want the result to be x = [2,5,[]] and that's automaticly
independently how deep i dig.



Sorry for the inconvenience.


Tamer



Am 10.08.2012 16:31, schrieb Chris Angelico:
> 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 | NextNext in thread | Find similar | Unroll thread


Thread

Re: dictionary into desired variable.... Tamer Higazi <th982a@googlemail.com> - 2012-08-10 17:31 +0200
  Re: dictionary into desired variable.... woooee@gmail.com - 2012-08-10 10:04 -0700
  Re: dictionary into desired variable.... woooee@gmail.com - 2012-08-10 10:04 -0700

csiph-web