Trying to do it with the mapping or dictionary type:
>>> x=['a','b']That's not what I want.. Instead:
>>> x
['a', 'b']
>>> y=['c','d']
>>> z={}
>>> z.fromkeys(x,y)
{'a': ['c', 'd'], 'b': ['c', 'd']}
>>> d=dict(zip(x,y))That's as close as I can get it.
>>> d
{'a': 'c', 'b': 'd'}
>>>
>>> d['a']It seems awkward, but if you put it in a loop, it looks fine:
'c'
>>> d['b']
'd'
>>> x=['a','b','c','d','e']
>>> y=['q','r','s','t','u']
>>> z=zip(x,y)
>>> z
[('a', 'q'), ('b', 'r'), ('c', 's'), ('d', 't'), ('e', 'u')]
>>> d=dict(z)
>>> d
{'a': 'q', 'c': 's', 'b': 'r', 'e': 'u', 'd': 't'}
>>> for key in x:
... print key, "=", d[key]
...
a = q
b = r
c = s
d = t
e = u
>>>
No comments:
Post a Comment