Skip to content

Instantly share code, notes, and snippets.

@sykire
Created September 22, 2017 03:48
Show Gist options
  • Save sykire/7a01318bdfefff13ae53f144e67f28b3 to your computer and use it in GitHub Desktop.
Save sykire/7a01318bdfefff13ae53f144e67f28b3 to your computer and use it in GitHub Desktop.
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