Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62056
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: Wrapping around a list in Python. |
| Date | 2013-12-16 07:51 -0500 |
| References | <e8123076-9f52-4a72-b262-908a5dcc8a10@googlegroups.com> <mailman.4181.1387171006.18130.python-list@python.org> <cf42bb27-a2c9-4a94-9c74-a6ff1253a2ee@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4212.1387198243.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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