Created
May 27, 2021 19:42
-
-
Save bruno-uy/ca4212d48c9824bcad6d432cfbaff5ee to your computer and use it in GitHub Desktop.
Usage and update of arguments in partial function
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 functools import partial | |
def print_n_dict_elem(n, dictionary, elem): | |
print(n * dictionary[elem]) | |
# Create a new function that print elem 3 times | |
print_3_dict_elem = partial(print_n_dict_elem, n=3, dictionary={"a": "A", "b": "B"}) | |
print_3_dict_elem(elem="a") | |
# Update dictionary passed as an argument | |
print_3_dict_elem.keywords["dictionary"].update({"c": "C"}) | |
print_3_dict_elem(elem="c") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @kchuang-homelight for the inspiration 🚀