Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'slices': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'trailing': 0.09; '(0,': 0.16; '16)': 0.16; 'alex23': 0.16; 'comma': 0.16; 'pid,': 0.16; 'row': 0.16; 'subject:Newbie': 0.16; 'this:': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'subject:list': 0.21; 'subject:Question': 0.21; 'dec': 0.22; 'wrote': 0.22; 'sun,': 0.30; 'quite': 0.32; 'does': 0.32; 'yet': 0.32; 'header:X -Complaints-To:1': 0.33; 'named': 0.33; 'to:addr:python-list': 0.34; 'thank': 0.35; 'but': 0.37; 'using': 0.38; 'received:org': 0.38; 'subject:from': 0.38; 'missing': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'frank': 0.64; '11,': 0.68; 'received:41': 0.71; '14)': 0.84; 'nice,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Newbie Question: Obtain element from list of tuples Date: Mon, 19 Dec 2011 08:46:28 +0200 References: <2c286dea-efba-45d5-85a7-a7503733575a@i6g2000vbe.googlegroups.com> <4eeea8eb$0$11091$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 41-135-99-54.dsl.mweb.co.za X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324277206 news.xs4all.nl 6853 [2001:888:2000:d::a6]:56505 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17500 "Steven D'Aprano" wrote in message news:4eeea8eb$0$11091$c3e8da3@news.astraweb.com... > On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: > >> Pre-namedtuple, I used to like using named slices for this: >> >> cPID = slice(19) >> pid = recs[cPID] > > You know, that is an incredibly simple thing and yet it never dawned on > me before now. Thank you for sharing that. > I also like it, but it does not work quite so simply for me. >>> row = tuple(range(20)) >>> cPID = slice(15) >>> pid = row[cPID] >>> pid (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) >>> This works - >>> row = tuple(range(20)) >>> cPID = slice(15, 16) >>> pid, = row[cPID] # note the trailing comma >>> pid 15 >>> Still nice, but not quite so elegant. Am I missing something? Frank Millman