values to tuple (['dev''mgr']'bob' list(bob items()items to tuple list [('jobs'['dev''mgr'])('name''bob')('age' )but with bit of extra workwe can implement objects that offer both positional and named access to record fields for examplethe namedtuple utilityavailable in the standard library' collections module mentioned in implements an extension type that adds logic to tuples that allows components to be accessed by both position and attribute nameand can be converted to dictionary-like form for access by key if desired attribute names come from classes and are not exactly dictionary keysbut they are similarly mnemonicfrom collections import namedtuple rec namedtuple('rec'['name''age''jobs']bob rec('bob'age= jobs=['dev''mgr']bob rec(name='bob'age= jobs=['dev''mgr']import extension type make generated class named-tuple record bob[ ]bob[ ('bob'['dev''mgr']bob namebob jobs ('bob'['dev''mgr']access by position access by attribute converting to dictionary supports key-based behavior when neededo bob _asdict(dictionary-like form ['name'] ['jobs'access by key too ('bob'['dev''mgr'] ordereddict([('name''bob')('age' )('jobs'['dev''mgr'])]as you can seenamed tuples are tuple/class/dictionary hybrid they also represent classic tradeoff in exchange for their extra utilitythey require extra code (the two startup lines in the preceding examples that import the type and make the class)and incur some performance costs to work this magic (in shortnamed tuples build new classes that extend the tuple typeinserting property accessor method for each named field that maps the name to its position-- technique that relies on advanced topics we'll explore in part viiiand uses formatted code strings instead of class annotation tools like decorators and metaclasses stillthey are good example of the kind of custom data types that we can build on top of built-in types like tuples when extra utility is desired named tuples are available in python (where _asdict returns true dictionary)and perhaps earlierthough they rely on features relatively modern by python standards they are also extensionsnot core types--they live in the standard library and fall into the same category as ' fraction and decimal--so we'll delegate to the python library manual for more details as quick previewthoughboth tuples and named tuples support unpacking tuple assignmentwhich we'll study formally in as well as the iteration contexts tuples