Newbie Question: Obtain element from list of tuples

HoneyMonster someone at someplace.invalid
Sun Dec 18 14:41:37 EST 2011


Hi,

I'm just starting to learn Python, so please bear with me. I have in my 
program an object (recs) which is a list of tuples (returned as such by a 
database query).

My question is doubtless a very easy one to answer: Say I want the ninth 
element in the twentieth tuple put into variable PID, I can do this, 
bearing in mind that numbering starts at zero:

tup = recs[19]
PID = tup[8]

But there must be an easier way; i.e. to do it in one go without the 
extra variable. How do I achieve that please?

Secondly, I am more than happy to read the fine manuals. If someone could 
point me in the direction of one or two "for idiots" guides, that would 
be greatly appreciated.




More information about the Python-list mailing list