I have a function that takes in a slice. What I want to do is to check if the end value in this slice is equal to -1. If that is the case, I want to reset the slice to another value. I can't find supporting documentation and do not know how to proceed.
datalist=[None, 'Grey', 'EE20-700', 'EE-42-01', 'EE15-767', 'EE0-70650', 'B&B', 1, 1, 1, 1, 1, '300R', True, 'Nov. 2, 2022', 'Nov. 2, 2022', 1, 1, 1, True, 3]
#If we just apply the given slice_dimensions, the following happens:
slice_dimensions=slice(1, -1)
datalist[slice_dimensions]
['Grey', 'EE20-700', 'EE-42-01', 'EE15-767', 'EE0-70650', 'B&B', 1, 1, 1, 1, 1, '300R', True, 'Nov. 2, 2022', 'Nov. 2, 2022', 1, 1, 1, True]
As you can see this is problematic, because the last element of my list (3) is omitted with the current slice dimension. I have seen many solutions saying I should use len(datalist)-1 or something similar instead, but this is not a workable option because the list lengths differ, and I want to keep it simple. If we can just check if end of slice is equal to -1 and change it to None, the problem is solved:
#If we just apply the given slice_dimensions, the following happens:
slice_dimensions=slice(1, None)
datalist[slice_dimensions]
['Grey', 'EE20-700', 'EE-42-01', 'EE15-767', 'EE0-70650', 'B&B', 1, 1, 1, 1, 1, '300R', True, 'Nov. 2, 2022', 'Nov. 2, 2022', 1, 1, 1, True, 3]
I would like to make a function to do so, but do not know how to proceed, something like this:
def slicer(slice_dimensions):
if slice_dimensions[1] == -1: #This part I do not know how to proceed
slice_dimensions= slice(1, None)
data_of_interest=datalist[slice_dimensions]
return(data_of_interest)
How should I proceed in doing so?