How to make a namedtuple from a list in Python

2 Answers

0 votes
import collections

Worker = collections.namedtuple("Worker", ["id", "name", "salary"])

values = [123, "tom", 13874]

tpl = Worker._make(values)

print(tpl)

 
'''
run:
 
Worker(id=123, name='tom', salary=13874)
 
'''

 



answered Nov 4, 2018 by avibootz
0 votes
import collections

Worker = collections.namedtuple("Worker", ["id", "name", "salary"])

values = [123, "tom", 13874]

tpl = Worker._make(values)

print(tpl.id)
print(tpl.name)
print(tpl.salary)

 
'''
run:
 
123
tom
13874
 
'''

 



answered Nov 4, 2018 by avibootz

Related questions

...