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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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