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


Groups > comp.lang.python > #62007

Re: Wrapping around a list in Python.

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'list?': 0.07; 'advance': 0.07; 'exceeds': 0.09; 'overwrite': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'shifting': 0.09; 'wrapped': 0.09; 'python': 0.11; 'guys,': 0.16; 'received:67.192.241.150': 0.16; 'received:smtp150.dfw.emailsrvr.com': 0.16; 'elements': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'value.': 0.19; 'example': 0.22; 'putting': 0.22; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'received:(smtp server)': 0.26; 'shown': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'fixed': 0.29; 'appreciated.': 0.29; 'subject:list': 0.30; "i'm": 0.30; 'gary': 0.31; 'lists': 0.32; 'beginning': 0.33; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'done,': 0.36; 'thanks': 0.36; 'list': 0.37; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'how': 0.40; 'easy': 0.60; 'tell': 0.60; 'numbers': 0.61; 'further': 0.61; 'first': 0.61; "you'll": 0.62; "you've": 0.63; 'grab': 0.64; 'telling': 0.64; 'spot': 0.65; 'email addr:live.com': 0.68; 'reverse': 0.68; 'of?': 0.84; 'snapshots': 0.84
X-Virus-Scanned OK
Date Sun, 15 Dec 2013 21:10:22 -0800
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Wrapping around a list in Python.
References <e8123076-9f52-4a72-b262-908a5dcc8a10@googlegroups.com>
In-Reply-To <e8123076-9f52-4a72-b262-908a5dcc8a10@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4181.1387171006.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387171006 news.xs4all.nl 2925 [2001:888:2000:d::a6]:37646
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62007

Show key headers only | 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