A dictionary list?

Lee Harr missive at frontiernet.net
Wed Dec 24 16:32:36 EST 2003


On 2003-12-24, Eli Pollak <eli at elipollak.com> wrote:
> Do you mean you want an iterable dictionary ?
> Such as in php :
>
>     $arr = array()
>     $arr[0] = 'a';
>     $arr[1] = 'b';
>     $arr['somestr'] = 'str';
>     $arr[2] = 'c';
>
>     foreach($arr as $element)
>         print $element
>
> which prints
>
>     'a','b','str','c'
>


Or, as in python, even ...

>>> arr = {}
>>> arr[0] = 'zero'
>>> arr[1] = 'one'
>>> arr['something'] = 'other'
>>> arr[3] = 'three'
>>> for x in arr:
...   print x, arr[x]
...
0 zero
1 one
3 three
something other
>>> [arr[x] for x in arr]
['zero', 'one', 'three', 'other']







More information about the Python-list mailing list