>>> t = [('a', 0), ('c', 2), ('b', 1)]
>>> d = dict(t)
>>> d
{'a': 0, 'c': 2, 'b': 1}
>>> d = dict(zip('abc', range(3)))
>>> d
{'a': 0, 'c': 2, 'b': 1}
>>> x = dict(enumerate('abc'))
>>> print(x)

{0: 'a', 1: 'b', 2: 'c'}

If you want to use a sequence as a dictionary key, you have to use an immutable type like a tuple or string.

results matching ""

    No results matching ""