alternate one liner implementation

This commit is contained in:
Azan Bin Zahid
2020-10-02 01:05:52 +05:00
committed by GitHub
parent 18eee212cc
commit 89941e0c55

View File

@ -5,14 +5,13 @@ tags: list,intermediate
Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value.
- Use a `for` loop to iterate over the list's values, assigning the values produced by `fn` to each key of the dictionary.
- Use `map` to apply `fn` to each value of the list.
- Use `zip` to pair original values to the values produced by `fn`.
- Use `dict` to return a key value pair.
```py
def map_dictionary(itr, fn):
ret = {}
for x in itr:
ret[x] = fn(x)
return ret
return dict(zip(itr, map(fn, itr)))
```
```py