Python - Namedtuple
** Namedtuple - When and why should you use namedtuples?
==========================================
from collections import namedtuple
color = (55, 155, 255)
print(color[0])
---------------------------------
55
---------------------------------
==========================================
from collections import namedtuple
color = {'red' : 55, 'green' : 155, 'blue' : 255}
print(color['red'])
---------------------------------
55
---------------------------------
==========================================
from collections import namedtuple
Color = namedtuple('Color', ['red', 'green', 'blue'])
color = Color(55, 155, 255)
print(color[0])
---------------------------------
55
---------------------------------
==========================================
from collections import namedtuple
Color = namedtuple('Color', ['red', 'green', 'blue'])
color = Color(55, 155, 255)
print(color.red)
---------------------------------
55
---------------------------------
==========================================
from collections import namedtuple
Color = namedtuple('Color', ['red', 'green', 'blue'])
dict_color = {'red': 55, 'green': 155, 'blue': 255}
color = Color(55, 155, 255)
white = Color(255, 255, 255)
print(white.blue)
---------------------------------
255
---------------------------------
==========================================
from collections import namedtuple
Color = namedtuple('Color', ['red', 'green', 'blue'])
dict_color = {'red': 55, 'green': 155, 'blue': 255}
color = Color(55, 155, 255)
white = Color(255, 255, 255)
print(dict_color['blue'])
---------------------------------
255
---------------------------------