slice last 4 items from a list

James Matthews nytrokiss at gmail.com
Tue Oct 2 02:25:16 EDT 2007


Very pythoninc!

On 10/1/07, John Machin <sjmachin at lexicon.net> wrote:
>
> On Oct 2, 6:27 am, brad <byte8b... at gmail.com> wrote:
> > Is this the correct way to slice the last 4 items from a list?
> >
> > x = [1,2,3,4,5,6,7,8,9]
> > print x[-4:]
> >
> > It works, but is it Pythonic?
>
> It's Pythonic. It's also unambiguous, unlike your specification, which
> could be interpreted as 'chop off the last 4 items from a list' i.e.
> del x[-4:]. What you are actually doing is 'print the last 4 items of
> a list'.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/search.aspx?Search=cufflinks
http://www.jewelerslounge.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071001/53947628/attachment.html>


More information about the Python-list mailing list