Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '[1,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'creates': 0.14; 'benjamin': 0.16; 'iterator': 0.16; 'loop.': 0.16; 'starred': 0.16; 'unpacking': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:gmail.com': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; '>>>': 0.24; 'convenient': 0.24; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'd": 0.34; 'problem': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'doing': 0.36; 'method': 0.36; 'subject:?': 0.36; 'list': 0.37; 'new': 0.61; 'numbers': 0.61; "you're": 0.61; "you'll": 0.62; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'oscar': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=Our6MUB7pjvu7iKEoF+whY7p9tJE4rgCnD0JbaWQugg=; b=GkXJ68i8BjCcsSJvv8ZDc4FERAeTuPV5kwhrnKz4ZQ8uuTILACHE2IbRn8Y4aXG1Y6 ptQUBZEui2Jx5EnZ1WHknNlPqhnfAs0Zdrh1rV8uuviSJqgSTXl9r5Hyxtsx6/LStm2y u2oSUqTMj+fAc2f+k7YUJqUJ+M5+yX/7MM+pgPoQCa4xcuVQ97U03NAqROK6kcKzYsjH oQhHQKmNmNT7+uVUWf30TwZvTQVg3F0sOTwe9TmXsYOZqCKsIlYIwMFPH+2zeNJkRwqU ggxwFlUYVHnmoxOUtG3A5Eq/GBRPDrWLxh1QHG+R7mMC2eelbVhhfnAwSRU1DnsSdHZw Kmxg== X-Received: by 10.112.3.202 with SMTP id e10mr16586746lbe.84.1366753301184; Tue, 23 Apr 2013 14:41:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Joshua Landau Date: Tue, 23 Apr 2013 22:41:00 +0100 Subject: Re: Nested iteration? To: Oscar Benjamin Content-Type: multipart/alternative; boundary=14dae9473a7903496f04db0e0d7a Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366753308 news.xs4all.nl 2275 [2001:888:2000:d::a6]:58494 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44221 --14dae9473a7903496f04db0e0d7a Content-Type: text/plain; charset=ISO-8859-1 On 23 April 2013 22:29, Oscar Benjamin wrote: > I just thought I'd add that Python 3 has a convenient way to avoid > this problem with next() which is to use the starred unpacking syntax: > > >>> numbers = [1, 2, 3, 4] > >>> first, *numbers = numbers > That creates a new list every time. You'll not want that over try-next-except if you're doing this in a loop, and on addition (if you were talking in context) your method will exhaust the iterator in the outer loop. --14dae9473a7903496f04db0e0d7a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 23 April 2013 22:29, Oscar Benjamin &= lt;oscar.j.= benjamin@gmail.com> wrote:
I just thought I'd add that Python 3 has a convenient way to avoid
this problem with next() which is to use the starred unpacking syntax:

>>> numbers =3D [1, 2, 3, 4]
>>> first, *numbers =3D numbers

That creates a new list every time. You'll not want that over t= ry-next-except if you're doing this in a loop, and on addition (if you = were talking in context) your method will exhaust the iterator in the outer= loop.
--14dae9473a7903496f04db0e0d7a--