First page Back Continue Last page Overview Graphics

Lists in Dictionaries, Python2

Python 2:

>>> k = ["a","b","c","d"]

>>> v = [232,343,543,23]

>>>

>>> zip(k,v)

[('a', 232), ('b', 343), ('c', 543), ('d', 23)]

>>>

>>> dict(zip(k,v))

{'a': 232, 'c': 543, 'b': 343, 'd': 23}

>>>

>>> d = dict(zip(k,v))

>>> d.items()

[('a', 232), ('c', 543), ('b', 343), ('d', 23)]

>>>

Python 3:

>>> k = ["a","b","c","d"]

>>> v = [232,343,543,23]

>>>

>>> zip(k,v)

<zip object at 0xb725640c>

>>>

>>> list(zip(k,v))

[('a', 232), ('b', 343), ('c', 543), ('d', 23)]

>>>

>>> dict(zip(k,v))

{'a': 232, 'c': 543, 'b': 343, 'd': 23}

>>>

>>> d = dict(zip(k,v))

>>>

>>> d.items()

dict_items([('a', 232), ('c', 543), ('b', 343), ('d', 23)])

>>>