slice last 4 items from a list

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Oct 1 16:32:38 EDT 2007


brad a écrit :
> 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?

Is there a more obvious (for a pythonic definition of 'obvious') way to 
do it ? If no, then it's pythonic... Now FWIW, I usually use 
'esrever'[::-1] to reverse a string, so I may not be a reference !-)



More information about the Python-list mailing list