Last active
May 5, 2020 07:57
-
-
Save raeq/3cfb3c9ad4f2a06f663e3c3308a33564 to your computer and use it in GitHub Desktop.
Compound Tuples
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
import collections | |
rgbvalue = collections.namedtuple("rgb", ["red", "green", "blue"]) | |
htmlcolour = collections.namedtuple("htmlcolour", ["name", "rgbvalue"]) | |
colours:set = set() | |
htmltuple = htmlcolour("Red", rgbvalue(red=0xff, green=0x00, blue=0x00)) | |
colours.add(htmltuple) | |
htmltuple = htmlcolour("Green", rgbvalue(blue=0x00,red=0x00,green=0xff)) | |
colours.add(htmltuple) | |
htmltuple = htmlcolour("Blue", rgbvalue(green=0x00,red=0x00,blue=0xff)) | |
colours.add(htmltuple) | |
htmltuple = htmlcolour("Chartreuse", rgbvalue(red=0x7f,blue=0x00,green=0xff)) | |
colours.add(htmltuple) | |
for colour in colours: | |
print (f"Nane: {colour.name}; " | |
f"Red value {colour.rgbvalue.red}, " | |
f"Green value {colour.rgbvalue.green}, " | |
f"Blue value {colour.rgbvalue.blue}." | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment