Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73209
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-06-12 00:13 -0700 |
| References | <8d6207ab-b883-4940-8e53-75546a91d4dd@googlegroups.com> <53992114.3040006@swing.be> <mailman.11026.1402545515.18130.python-list@python.org> <814a6cb2-6e62-4c21-acca-71e30b22ec9f@googlegroups.com> <53993e0e$0$11121$c3e8da3@news.astraweb.com> |
| Message-ID | <cb941262-2271-4f4c-9f7e-63fe3cd14fca@googlegroups.com> (permalink) |
| Subject | Re: About python while statement and pop() |
| From | hito koto <hitokoto2014@gmail.com> |
2014年6月12日木曜日 14時43分42秒 UTC+9 Steven D'Aprano: > On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote: > > > > > I want to use while statement, > > > > > > for example: > > >>>> def foo(x): > > > ... y = [] > > > ... while x !=[]: > > > ... y.append(x.pop()) > > > ... return y > > > ... > > >>>> print foo(a) > > > [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]] > > >>>> a > > > [] but this is empty > > >>>> so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7, > > >>>> 8, 9],[10]]) > > > > > > I wouldn't use a while statement. The easy way is: > > > > py> a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]] > > py> y = a[::-1] > > py> print y > > [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]] > > py> print a > > [[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]] > > > > If you MUST use a while loop, then you need something like this: > > > > > > def foo(x): > > y = [] > > index = 0 > > while index < len(x): > > y.append(x[i]) > > i += 1 > > return y > > > > > > This does not copy in reverse order. To make it copy in reverse order, > > index should start at len(x) - 1 and end at 0. > > > > > > > > -- > > Steven Hi, Steven: Thanks, My goal is to be able to in many ways python Sorry, I was mistake, I want to leave a number of previous (a = [[10], [9, 8, 7, 6, 5], [4, 3, 2, 1]] )
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
About python while statement and pop() hito koto <hitokoto2014@gmail.com> - 2014-06-11 20:12 -0700
Re:About python while statement and pop() Dave Angel <davea@davea.name> - 2014-06-11 22:34 -0500
Re: About python while statement and pop() Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2014-06-12 05:40 +0200
Re: About python while statement and pop() Chris Angelico <rosuav@gmail.com> - 2014-06-12 13:58 +1000
Re: About python while statement and pop() hito koto <hitokoto2014@gmail.com> - 2014-06-11 21:56 -0700
Re: About python while statement and pop() Chris Angelico <rosuav@gmail.com> - 2014-06-12 15:08 +1000
Re: About python while statement and pop() Steven D'Aprano <steve@pearwood.info> - 2014-06-12 05:43 +0000
Re: About python while statement and pop() hito koto <hitokoto2014@gmail.com> - 2014-06-11 23:06 -0700
Re: About python while statement and pop() hito koto <hitokoto2014@gmail.com> - 2014-06-12 00:13 -0700
Re: About python while statement and pop() hito koto <hitokoto2014@gmail.com> - 2014-06-12 02:51 -0700
Re: About python while statement and pop() Mark H Harris <harrismh777@gmail.com> - 2014-06-12 11:41 -0500
Re: About python while statement and pop() Mark H Harris <harrismh777@gmail.com> - 2014-06-12 11:49 -0500
Re: About python while statement and pop() Marko Rauhamaa <marko@pacujo.net> - 2014-06-12 19:55 +0300
Re: About python while statement and pop() Mark H Harris <harrismh777@gmail.com> - 2014-06-12 12:07 -0500
Re: About python while statement and pop() Chris Angelico <rosuav@gmail.com> - 2014-06-13 02:57 +1000
Re: About python while statement and pop() Mark H Harris <harrismh777@gmail.com> - 2014-06-12 12:10 -0500
Re: About python while statement and pop() Mark H Harris <harrismh777@gmail.com> - 2014-06-12 12:16 -0500
Re: About python while statement and pop() wxjmfauth@gmail.com - 2014-06-12 11:37 -0700
csiph-web