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


Groups > comp.lang.python > #62056

Re: Wrapping around a list in Python.

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!diablo1.news.osn.de!news.osn.de!diablo2.news.osn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'assuming': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'array.': 0.16; 'elements,': 0.16; 'list)': 0.16; 'popping': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'example': 0.22; 'header:User- Agent:1': 0.23; 'earlier': 0.24; '(or': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'array': 0.29; 'dec': 0.30; 'subject:list': 0.30; 'continues': 0.31; '"the': 0.34; 'advice': 0.35; 'display': 0.35; 'but': 0.35; 'really': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'how': 0.40; "you're": 0.61; 'such': 0.63; 'grab': 0.64; 'email addr:live.com': 0.68; 'goal': 0.75; 'results,': 0.84; 'hundred': 0.95; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: Wrapping around a list in Python.
Date Mon, 16 Dec 2013 07:51:49 -0500
References <e8123076-9f52-4a72-b262-908a5dcc8a10@googlegroups.com> <mailman.4181.1387171006.18130.python-list@python.org> <cf42bb27-a2c9-4a94-9c74-a6ff1253a2ee@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host dpc6744192126.direcpc.com
In-Reply-To <cf42bb27-a2c9-4a94-9c74-a6ff1253a2ee@googlegroups.com>
User-Agent Groundhog Newsreader for Android
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.4212.1387198243.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387198243 news.xs4all.nl 2872 [2001:888:2000:d::a6]:57942
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62056

Show key headers only | View raw


On Sun, 15 Dec 2013 21:26:49 -0800 (PST), shengjie.shengjie@live.com 
wrote:
> The idea is to grab the last 4 elements of the array. However i 
have an array that contains a few hundred elements in it. And the 
values continues to .append over time. How would i be able to display 
the last 4 elements of the array under such a condition?

Your earlier example showed [5, 4, 1, 2] as one of the results, which 
is not "the last four". But assuming your goal has now changed and 
you really have an array (or list) of a few hundred elements,  then 
you can just use data [-4:] to get them. 

But if you're being imprecise and these values are not really in an 
array, then follow Peter ' advice and use a deque. Or fake it with a 
list,  appending to the end and popping from the beginning.

-- 
DaveA

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