Created
February 22, 2021 00:46
-
-
Save leveled/ad354747be88eb248dd7ecbac7519c58 to your computer and use it in GitHub Desktop.
Capture all keyword arguments provided to a function in Python
This file contains hidden or 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
def tag(tag_name, **attributes): | |
attribute_list = [ | |
f'{name}="{value}"' | |
for name, value in attributes.items() | |
] | |
return f"<{tag_name} {' '.join(attribute_list)}>" | |
>>> tag('a', href="http://treyhunner.com") | |
'<a href="http://treyhunner.com">' | |
>>> tag('img', height=20, width=40, src="face.jpg") | |
'<img height="20" width="40" src="face.jpg">' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment