how to convert list of pairs to a map grouped by o...
# getting-started
s
how to convert list of pairs to a map grouped by one component e.g. second?
Copy code
`listOf("A" to 1, "B" to 2, "C" to 1)` to `mapOf(1 to listOf("A", "C"), 2 to listOf("B"))`
👍 1
a
use
groupBy
j
Copy code
listOf("A" to 1, "B" to 2, "C" to 1).groupBy( { it.second}, { it.first})
s
Thanks @Joris PZ, yeah! Just figured it out by following @allan.conda’s pointer