Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17474

Re: Newbie Question: Obtain element from list of tuples

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 <arnodel@gmail.com>
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 <jclflh$u45$1@news.albasani.net>
References <jclflh$u45$1@news.albasani.net>
Date Sun, 18 Dec 2011 19:49:34 +0000
Subject Re: Newbie Question: Obtain element from list of tuples
From Arnaud Delobelle <arnodel@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3804.1324237776.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 18 December 2011 19:41, HoneyMonster <someone@someplace.invalid> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Newbie Question: Obtain element from list of tuples HoneyMonster <someone@someplace.invalid> - 2011-12-18 19:41 +0000
  Re: Newbie Question: Obtain element from list of tuples Arnaud Delobelle <arnodel@gmail.com> - 2011-12-18 19:49 +0000
  Re: Newbie Question: Obtain element from list of tuples Roy Smith <roy@panix.com> - 2011-12-18 15:04 -0500
    Re: Newbie Question: Obtain element from list of tuples HoneyMonster <someone@someplace.invalid> - 2011-12-18 20:22 +0000
      Re: Newbie Question: Obtain element from list of tuples Roy Smith <roy@panix.com> - 2011-12-18 15:25 -0500
    Re: Newbie Question: Obtain element from list of tuples alex23 <wuwei23@gmail.com> - 2011-12-18 18:35 -0800
      Re: Newbie Question: Obtain element from list of tuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-19 03:00 +0000
        Re: Newbie Question: Obtain element from list of tuples "Frank Millman" <frank@chagford.com> - 2011-12-19 08:46 +0200
          Re: Newbie Question: Obtain element from list of tuples DevPlayer <devplayer@gmail.com> - 2011-12-19 07:37 -0800
          Re: Newbie Question: Obtain element from list of tuples alex23 <wuwei23@gmail.com> - 2011-12-19 19:53 -0800
  Re: Newbie Question: Obtain element from list of tuples Chris Angelico <rosuav@gmail.com> - 2011-12-19 07:51 +1100
    Re: Newbie Question: Obtain element from list of tuples Roy Smith <roy@panix.com> - 2011-12-18 16:10 -0500
    Re: Newbie Question: Obtain element from list of tuples HoneyMonster <someone@someplace.invalid> - 2011-12-18 22:55 +0000
      Re: Newbie Question: Obtain element from list of tuples Chris Angelico <rosuav@gmail.com> - 2011-12-19 10:40 +1100
        Re: Newbie Question: Obtain element from list of tuples HoneyMonster <someone@someplace.invalid> - 2011-12-20 00:59 +0000

csiph-web