Last active
July 29, 2021 05:52
-
-
Save FerdinaKusumah/ba9349fe0bc0cce4d4849f5d9b23b615 to your computer and use it in GitHub Desktop.
Python Namedtuple
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
from collections import namedtuple | |
HobbyNameTuple = namedtuple("Hobby", ["name"]) | |
StudentNameTuple = namedtuple("Student", ["name", "age", "hobby"]) | |
if __name__ == "__main__": | |
h = HobbyNameTuple("swimming") | |
s = StudentNameTuple("John toer", 18, [h._asdict()]) | |
result = s._asdict() | |
print(result) | |
# result is | |
# {'name': 'John toer', 'age': 18, 'hobby': [{'name': 'swimming'}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment