dictionary into desired variable....

Tamer Higazi th982a at googlemail.com
Fri Aug 10 11:31:48 EDT 2012


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




More information about the Python-list mailing list