given a map with possibly repeated values, is the ...
# getting-started
n
given a map with possibly repeated values, is the following best way to reverse it (to a Map<V, List<K>>)
Copy code
fun <K, V> Map<K, V>.reverse(): Map<V, List<K>> = entries.groupBy { it.value }.map { it.key to it.value.map { it.key } }.toMap()
d
entries.groupBy({ it.value }, { it.key })
👌 1
n
Nice, thanks!
k
btw I think the right terminology is "invert".