Python lists have nifty indexing/slicing capabilities. Here are several examples:
x = "123456"
x[:-3]
'123'
x[:-1]
'12345' # -1 slices off last element
x[:-0] # -0 slices off .. everything .. this is what i'd like to fix
''
I would like to slice off a variable number of elements d:
x[:-d]
But if d were 0 we get a much different result than desired. A workaround is:
d = 0
x[:-d if d else len(x)]
'123456'
That is possible - but is there any [shorter] alternative?