Python3: Given two sequences/iterators create a dictionary

Paul Yeo
Dec 6, 2020
a = "ABC", b = "123"
dict(zip(a, b))
# {"A": "1", "B": "2", "C": "3"}

zip() returns an iterator of tupes where the i-th tuple contains the i-th element from each of the argument sequences or iterators.

dict() constructor builds dictionaries directly from sequences of key-value pairs.

--

--