I am trying to sublist an list which contains long.
a = [ -846930886, -1714636915, 424238335, -1649760492]
print(a[2:1])
This returns []
. What's happening? I could find only this way of sub listing.
I am trying to sublist an list which contains long.
a = [ -846930886, -1714636915, 424238335, -1649760492]
print(a[2:1])
This returns []
. What's happening? I could find only this way of sub listing.
a[2:1]
is not a valid slicing
and will return empty
list.
The correct syntax is object[start:end:inteval]
. If you want to traverse in backward you should add interval
>>> print(a[2:1:-1])
[424238335]
Another approach will be with passing single index
>>> print(a[-2])
424238335
Or if you want to traverse in forward direction use :
>>> print(a[1:2])
[-1714636915]
Your sublist starts after it ends.So,
print(a[1:2])
will give you
[-1714636915].