On 03/06/2015 22:08, Rustom Mody wrote:
On Tuesday, June 2, 2015 at 7:50:58 PM UTC+5:30, Ian wrote:
On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody  wrote:
For that matter even this works
But I am not sure whats happening or that I like it

[x[-2:]  for x in lines]
['12', '42', '49', '56', '25', '36', '49', '64', '81', '00']

x[-2:] selects all items in the sequence with index i such that len(x)
- 2 <= i < len(x). For a sequence of length 2 or less, that's the
entire sequence.

Thanks -- learn something
So it means that indices can give indexerror; slices cannot?
Seems fair enough put that way, but is visually counterintuitive


Are you seriously trying to say that you teach Python but don't understand a basic that is here https://docs.python.org/3/tutorial/introduction.html, "Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced."?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to