Get the values ​of a tuple in other a tuple

Viewed 41

I'm trying to get the first value of each Key. But I don't know how to get that value from a tuple in other a tuple.

(Key1(typekey=10, typecod=11),Key2(typekey=12, typecod=10)...)

This is the return from a database and I would need to make a column called "Keys" and the rows would be given [typekey=10],[typekey=12]... .

Like that:

Keys

typekey=10
typekey=12
...

If anyone knows how I can do this I appreciate it.

1 Answers

These are named tuples, so you can access the elements as attributes.

Simply do this in a loop over the outer tuple.

for row in yourTuple:
    print(f"typekey={row.typekey}")
Related