Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'subject:()': 0.09; 'subject:while': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'be:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'reversed': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'subject:About': 0.31; 'though.': 0.31; 'probably': 0.32; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'changing': 0.37; 'list': 0.37; 'pm,': 0.38; '12,': 0.39; 'new': 0.61; 'simply': 0.61; 'first': 0.61; 'for:': 0.64; 'more': 0.64; 'reverse': 0.68; 'yours': 0.88; 'thing,': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=gfqYuuKyKbCRJw8RFDc3GPt2ZHUOHqjQUln81c4LMkk=; b=fQuFeSnUjC7dYW0rQzg030YsIQS06cSmi1O1G0fpeFLtVxGIirslFh6+luav28kj4W w0zGBCEGOmleWQIpOSfDnrrsoYW/ed8NnC8TXnRTWKNpCviMAfkPA09NFLK75CuiYktX 7fTF2lmNv0UPWDICDzxo1m5qqhBZFwFDmzfGz7gknz7b34nDm8hsB+cQ9raLoC4o+eFW ObBhhKkyHkiLJhHlpWOUIYPP13VbACrbfYKyjlyKt/JvqQClaGraF0TC9WmjFjbVv+KE 3sz2u4qfmqFCX+VUn4GGiyaVOuYkk7RNP2xyjr4hjjBxRDYGa9p9F3X+BD9qgdKy6ri7 oCDQ== MIME-Version: 1.0 X-Received: by 10.52.244.84 with SMTP id xe20mr6279453vdc.3.1402545507184; Wed, 11 Jun 2014 20:58:27 -0700 (PDT) In-Reply-To: <53992114.3040006@swing.be> References: <8d6207ab-b883-4940-8e53-75546a91d4dd@googlegroups.com> <53992114.3040006@swing.be> Date: Thu, 12 Jun 2014 13:58:27 +1000 Subject: Re: About python while statement and pop() From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402545515 news.xs4all.nl 2885 [2001:888:2000:d::a6]:37360 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73199 On Thu, Jun 12, 2014 at 1:40 PM, Vincent Vande Vyvre wrote: > Le 12/06/2014 05:12, hito koto a =C3=A9crit : > >> Hello,all >> I'm first time, >> >> I want to make a while statement which can function the same x.pop () an= d >> without the use of pop=E3=80=81how can i to do? >> >> i want to change this is code: >> >> def foo(x): >> y =3D [] >> while x !=3D[]: >> y.append(x.pop()) >> return y > > Something like that : > > def foo(x): > return reversed(x) That doesn't do the same thing, though. Given a list x, the original function will empty that list and return a new list in reverse order, but yours will return a reversed iterator over the original list without changing it. This is more accurate, but still not identical, and probably not what the OP's teacher is looking for: def foo(x): y =3D x[::-1] x[:] =3D [] return y If the mutation of x is unimportant, it can simply be: def foo(x): return x[::-1] ChrisA