将成对的列表收集到地图中 [英] Collect a list of pairs into a map
本文介绍了将成对的列表收集到地图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何将值对列表的列表收集到映射中,其中将所述对转换为映射中的key:value
项,如:
How can we collect a list of lists of value pairs into a map where said pairs are transformed into key:value
entries in the map, as in:
a = [[1,11], [2,22], [3,33]]
b = ...?
assert b == [1:11, 2:22, 3:33]
推荐答案
Because collectEntries
works with a pair list, you can just do
def b = a.collectEntries()
这篇关于将成对的列表收集到地图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文