Given the following list:
a = [0,1,2,3,4,5]
In python I can do this:
a[2:4]
which will get me [2,3]
Given that same list in groovy, is there a similar slicing mechanism I can use?
Python supports slice assignment operation, which allows us to make a bunch of neat operations over an existing list. Unlike previous slice operations, these mutate the original object in place. That's why they are not applicable to immutable sequential types.
The answer is:
a[2..3]
another example would be if you wanted [1,2,3,4]:
a[1..4]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With