rList = [[[12, 'name1'], [22, 'name2'], [49, 'name3']], [[33, 'name5'], [22, 'name6'], [21, 'name7']]] names = rList[0]*.getAt(1) assert names == ['name1', 'name2', 'name3']
First, rList[0]
provides you with the first sub-list, which is [[12, name1], [22, name2], [49, name3]]
. Then the distribution operator , *.
used to apply the same getAt(1)
method to every element of this list, which will return a list with every second element of the subscriptions, which are the values ββyou were looking for :)
You can also use rList[0].collect { it[1] }
, which is equivalent and might be more familiar if you do not use the distribution operator.
source share