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: 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 Subject: Re: Wrapping around a list in Python. Date: Mon, 16 Dec 2013 07:51:49 -0500 References: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: dpc6744192126.direcpc.com In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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