Is there any clean way to get a list item's field in a for loop, i.e. directly iterating over the field values without explicitly getting it in the loop itself. Example:
from collections import namedtuple
Person = namedtuple("Person", ["name", "age"])
p1 = Person("Bob", 42)
p2 = Person("Sam", 19)
l = [p1, p2]
for p in l:
p_name = p.name
print(p_name)
I would like to get the parameter p_name
from the for
declaration. The use of tuples is only for example, the solution should work also for objects and preferably for dict