Gijs
Gijs

Reputation: 143

Groovy list of lists to map with first list as keys

How would I go in Groovy idiomatically (with collection methods?) from

[['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]]

to

[[a: 1, b: 2, c: 3], [a: 4, b: 5, c: 6]]

Upvotes: 0

Views: 123

Answers (1)

daggett
daggett

Reputation: 28564

def x=[['a', 'b', 'c'], [1, 2, 3], [4, 5, 6]]

x.tail().collect{v-> x.head().indexed().collectEntries{i,k-> [k, v[i]] } }

Upvotes: 3

Related Questions