map()
to apply fn
to each value of the list.zip()
to pair original values to the values produced by fn
.dict()
to return an appropriate dictionary.def map_dictionary(itr, fn): return dict(zip(itr, map(fn, itr)))
map_dictionary([1, 2, 3], lambda x: x * x) # { 1: 1, 2: 4, 3: 9 }
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️