How do i create a slice() object so that it would include the last element of a list/string
s = 'abcdef'
s[slice(2,4)]
works fine.
Say I wanted to get elements from second to the end, the equivalent of s[2:]
s[slice(2)] # only gives first two elements, argument is interpreted as the end of the range
s[slice(2,)] # same as above
s[slice(2, -1)] # gives a range from second to the end excluding the last element
s[slice(2, 0)] # gives empty as expected, since end of range before the start
I can get specifically the last element with slice(-1, -2, -1), this won't work correctly for more then one element.