a clean way to define dictionary
Alex Martelli
aleax at aleax.it
Wed Jun 18 04:22:06 EDT 2003
Bryan wrote:
...
> dict(zip(lst[0::2], map(eval, lst[1::2])))
Note: 2.3 only -- lists didn't support extended-slicing in Python 2.2.
> also, i don't think it's a good idea to use dict as a variable name since
> dict is a python type.
Very good advice! If you use dict as a local name, you shadow the
buit-in name 'dict' and therefore cannot any more call it e.g. in
order to generate a new dictionary, as above.
Alex
More information about the Python-list
mailing list