TL; DR:
myslice = myslice[:len(myslice) - 1]
By the way, this will happen if "myslice" is zero size.
Longer answer:
myslice = myslice[:len(myslice) - 1]
This will happen if "myslice" is zero size.
Slopes are data structures that point to a base array, and operations, such as slice slice, use the same base array.
This means that if you slice a slice, the new slice will still point to the same data as the original slice.
Performing the above, the last element will still be in the array, but you can no longer reference it.
Edit
Explanation: If you cut the slice to its original length, you can refer to the last object
/ Edit
If you have a really large fragment, and you also want to trim the base array to save memory, you probably want to use a โcopyโ to create a new slice with a smaller base array and allow the old large fragment to collect garbage.
DallaRosa
source share