May 2017
Intermediate to advanced
280 pages
6h 2m
English
In the next example, we will understand how to add list values into namedtuple and how to make dictionary from namedtuple:
import collectionsemployee = collections.namedtuple('emp','name, age, empid')list1 = ['BOB', 21, 34567]record2 =employee._make(list1)print record2print "n"print (record2._asdict())
Here, by using _make, we can add a list into a namedtuple and by using _asdict we can create dictionary of namedtuple:

Now, consider a scenario where you would like to replace a value from namedtuple. Like tuple, the namedtuple is also immutable. But you can use the _replace function to replace the ...
Read now
Unlock full access