get last two in a length of unknown length?

wes weston wweston at att.net
Thu Aug 19 13:59:41 EDT 2004


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
> 
> 
M,
    Note this, maybe, unexpected behavior:

 >>> list=[1]
 >>> list[-2:]
[1]

 >>> list = []
 >>> list[-2:0]
[]

wes




More information about the Python-list mailing list