Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.01; 'python.': 0.04; 'tuple': 0.09; 'way;': 0.09; 'received:209.85.214.174': 0.13; 'constants': 0.16; 'numbering': 0.16; 'pid,': 0.16; 'subject:Newbie': 0.16; 'variable.': 0.16; 'zero:': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'please?': 0.18; 'cc:no real name:2**0': 0.20; 'subject:list': 0.21; 'subject:Question': 0.21; 'header:In-Reply-To:1': 0.22; 'starts': 0.24; 'cc:2**0': 0.24; "i'm": 0.26; 'variable': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'tuples': 0.30; 'usually': 0.31; 'hi,': 0.32; 'list': 0.32; 'received:209.85.214': 0.32; 'there': 0.33; 'object': 0.33; 'starting': 0.36; 'question': 0.36; 'element': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'put': 0.38; 'subject:from': 0.38; 'easier': 0.38; 'i.e.': 0.39; 'received:209': 0.40; '2011': 0.61; 'achieve': 0.61; 'bear': 0.64; 'note:': 0.69; 'ninth': 0.91; 'to:none': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=vmTaDvPT4I5rxVL0sK+b6EApQfN3FbBBnlrUflIKzlM=; b=HfYkB/jRIA7OClTjYGBXJGJb0aOW903Npolue7eA9PBkxIQn6Z9X9x4JOQS0zuqNy4 PMw0axDAZci6KqEjj9xgBGDeZAyOUF6GBxPZGQzIeD0DiLDHD8lYeGweASSWxAy1SqOE kJa7O2KzRHmdnQScZeLhnrumCKsgm9T6IR2yc= MIME-Version: 1.0 In-Reply-To: References: Date: Sun, 18 Dec 2011 19:49:34 +0000 Subject: Re: Newbie Question: Obtain element from list of tuples From: Arnaud Delobelle Cc: python-list@python.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324237776 news.xs4all.nl 6904 [2001:888:2000:d::a6]:51227 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17474 On 18 December 2011 19:41, HoneyMonster wrote: > 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? Well, you were almost there: pid = recs[19][8] Note: all caps is usually reserved for constants in Python. -- Arnaud