get last two in a length of unknown length?
indigo at bitglue.com
Thu Aug 19 18:58:25 CEST 2004
A negative index counts from the end, so:
l = [0,1,2,3,4]
l[-1] == 4
this works for slices too:
l[-2:] == [3,4]
On Thu, Aug 19, 2004 at 03:45:47AM +0100, M. Clift wrote:
> Hi All,
> I have a list of varying length. Would someone know the way to get the last
> two values for this? I can see how this is done with a list that I know the
> length of, but not one thats generated by user input.
> Thanks for any help
More information about the Python-list