namedtuple in Python

You can access the fields of a namedtuple by using dot notation (obj.attr). It's faster than dictionary.

from collections import namedtuple

# ['name', 'ranking'] 是 field names
ProgrammingLang = namedtuple('ProgrammingLang', ['name', 'ranking'])

python = ProgrammingLang('Python 3.4', 1)
java = ProgrammingLang('Java 8', 2)
go = ProgrammingLang('Go 1.5', 12)

print(python.name)
print(python.ranking)

ref:
http://www.reddit.com/r/Python/comments/38ee9d/intro_to_namedtuple/
https://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields