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


Groups > comp.lang.python > #62007

Re: Wrapping around a list in Python.

Date 2013-12-15 21:10 -0800
From Gary Herron <gary.herron@islandtraining.com>
Subject Re: Wrapping around a list in Python.
References <e8123076-9f52-4a72-b262-908a5dcc8a10@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4181.1387171006.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/15/2013 08:38 PM, shengjie.shengjie@live.com wrote:
> Hi guys, I am trying to create a fixed list which would allow my values to be wrapped around it.
> For example i have 10 values : 0,1,2,3,4,5,6,7,8,9
> I need to create a list which contains 4 numbers and when the number exceeds the list, it would overwrite the first value.
> [0,1,2,3]
> [4,1,2,3]
> [5,4,1,2]
>
> Thanks in advance and much help appreciated.

Is the output really three lists as you show.  Or is that one list whose 
contents you have shown three snapshots of?  Then what was the point of 
putting 4 in the first spot when you are just going to move it to the 
second spot?  And why stop at 4 and 5?  What about 7, 8, and 9?

Are you really shifting elements onto the beginning of the list and off 
the end of the list?  (That's easy to do, but is that what you want?)

If I follow your example a few elements further I get [9,8,7,6], just 
the last four elements of the original list in reverse order -- so there 
is no need fill a list and "wrap-around"  -- just grab the last four 
elements and reverse them.

Or have I misunderstood the problem completely?  (I think that's 
likely.)  I'm sure Python is general enough to do what you want, but 
you'll have to do a much better job telling is what you want.  While you 
are at it, tell us what you've already done, and how it fails to do 
whatever it is you want.

Gary Herron

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


Thread

Wrapping around a list in Python. shengjie.shengjie@live.com - 2013-12-15 20:38 -0800
  Re: Wrapping around a list in Python. Ben Finney <ben+python@benfinney.id.au> - 2013-12-16 15:59 +1100
    Re: Wrapping around a list in Python. shengjie.shengjie@live.com - 2013-12-15 21:07 -0800
      Re: Wrapping around a list in Python. shengjie.shengjie@live.com - 2013-12-15 21:10 -0800
        Re: Wrapping around a list in Python. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-16 09:33 +0000
    Re: Wrapping around a list in Python. Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-16 10:12 +0000
  Re: Wrapping around a list in Python. Gary Herron <gary.herron@islandtraining.com> - 2013-12-15 21:10 -0800
    Re: Wrapping around a list in Python. shengjie.shengjie@live.com - 2013-12-15 21:26 -0800
      Re: Wrapping around a list in Python. Peter Otten <__peter__@web.de> - 2013-12-16 10:15 +0100
      Re: Wrapping around a list in Python. David Robinow <drobinow@gmail.com> - 2013-12-16 07:41 -0500
      Re: Wrapping around a list in Python. Dave Angel <davea@davea.name> - 2013-12-16 07:51 -0500
  Re: Wrapping around a list in Python. shengjie.shengjie@live.com - 2013-12-15 21:26 -0800

csiph-web