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


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

Re: dictionary into desired variable....

Started byTamer Higazi <th982a@googlemail.com>
First post2012-08-10 17:31 +0200
Last post2012-08-10 10:04 -0700
Articles 3 — 2 participants

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.... 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

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

FromTamer Higazi <th982a@googlemail.com>
Date2012-08-10 17:31 +0200
SubjectRe: dictionary into desired variable....
Message-ID<mailman.3166.1344612712.4697.python-list@python.org>
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

[toc] | [next] | [standalone]


#26881

Fromwoooee@gmail.com
Date2012-08-10 10:04 -0700
Message-ID<mailman.3169.1344618284.4697.python-list@python.org>
In reply to#26877
On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote:
> 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

There is no such thing as a[3] if a=[2,4,5].  And this is a list not a dictionary, so I would suggest a tutorial from the Python wiki page.

You have to use a mutable container.  Integers are not mutable.  Lists, for example are.

y=[4]
x = [2,5,y]
print x
y[0]=10
print x

[toc] | [prev] | [next] | [standalone]


#26882

Fromwoooee@gmail.com
Date2012-08-10 10:04 -0700
Message-ID<d6c5ac27-be53-4074-bf54-80e8c303d183@googlegroups.com>
In reply to#26877
On Friday, August 10, 2012 8:31:48 AM UTC-7, Tamer Higazi wrote:
> 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

There is no such thing as a[3] if a=[2,4,5].  And this is a list not a dictionary, so I would suggest a tutorial from the Python wiki page.

You have to use a mutable container.  Integers are not mutable.  Lists, for example are.

y=[4]
x = [2,5,y]
print x
y[0]=10
print x

[toc] | [prev] | [standalone]


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


csiph-web