Skip to content

Instantly share code, notes, and snippets.

@raeq
Last active May 5, 2020 07:57
Show Gist options
  • Save raeq/3cfb3c9ad4f2a06f663e3c3308a33564 to your computer and use it in GitHub Desktop.
Save raeq/3cfb3c9ad4f2a06f663e3c3308a33564 to your computer and use it in GitHub Desktop.
Compound Tuples
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