+ 2
Beginner's question about slicing
I wonder if I'll ever need it, but... somelist[-3:-1] will give me a slice without the last element. Is there a way to get the last element while still counting from the back? 0 obviously can not work.
4 ответов
+ 6
Yeah, Jan Markus ' version is the standard. I'm nowhere near familiar with list slicing.
https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation
+ 3
somelist[-1:-4:-1]
+ 2
I'm aware that there are ways to circumvent the issue, but just out of interest: is there a way to get the index of the position rightside of - 1 directly?
+ 2
Haha, how about this? ;-)
[1,2,3][-1:-4:-1][::-1]
Not exactly as concise as I'd like it to be though... :D
Or do you find it concise, Denise Roßberg?