Created
September 22, 2017 03:48
-
-
Save sykire/7a01318bdfefff13ae53f144e67f28b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Callable, Dict | |
def map_dict(func: Callable, dictionary: Dict): | |
''' | |
Returns a dict with the same keys as `dictionary` and with its | |
values mapped over `func` | |
wallet = {'Peter': 20, 'John': 35} | |
wallet_squared = map_dict(lambda m: m**2, wallet) | |
''' | |
return dict(zip(dictionary.keys(), map(func, dictionary.values()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment