Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Created October 16, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3ik0th/c8881391b727bf070c10c6a5a5f0ae78 to your computer and use it in GitHub Desktop.
Save h3ik0th/c8881391b727bf070c10c6a5a5f0ae78 to your computer and use it in GitHub Desktop.
# on the web, I've seen an alternative:
# the use of functions with a loop to unpack and print dictionary items
# the double asterisk ** in the function call unpacks the dictionary
# the **kwargs argument accepts an undetermined number of keyword arguments
# it needs 4 lines of code where the list comprehension needed 1 to print the dictionary
def print_dict(**kwargs):
for key,value in kwargs.items():
print(f'{key}:{value:.1f}')
# call function:
print_dict(**acc_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment