lundi 2 juin 2014

Indexing lists in python, for a range of values


Vote count:

0




Getting late and I haven't the strength to work this out :S


To my knowledge, indexing with -1 will bring you up the last item in a list e.g.



list = 'ABCDEFG'
list[-1]
'G'


But when you are asking for a sequence from the list, -1 gives the second to last term in a list,



list[3:-1]
'DEF'


Why? I would have expected, and would like to get DEFG.


Thank you.



asked 27 secs ago






Aucun commentaire:

Enregistrer un commentaire