Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python like list slicing in Groovy [duplicate]

Tags:

python

groovy

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?

like image 841
Mike Sallese Avatar asked Sep 30 '16 17:09

Mike Sallese


People also ask

Does slicing mutate Python?

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.


1 Answers

The answer is:

a[2..3]

another example would be if you wanted [1,2,3,4]:

a[1..4]

like image 118
Mike Sallese Avatar answered Sep 23 '22 11:09

Mike Sallese