I was wondering if there's a one line solution to print out a range from a potential negative index to a positive.
For example:
a = [1,2,3,4,5,6,7,8]
x1 = 2
x2 = 5
print(a[x1:x2]) # [3, 4, 5]
If x1 is negative, I want it to go from the negative index to whatever x2 is. So if x1 = -2
the result should be: [7, 8, 1, 2, 3, 4, 5]
However, currently this will return an empty list.
I could solve this by
x1 = -2
if x1 < 0:
x = a[x1:] + a[:x2]
print(x) #[7, 8, 1, 2, 3, 4, 5]
But I was wondering if there is a one line solution to this?