根据第二个列表从列表中提取字段 [英] Pulling a field from a list based on second list
本文介绍了根据第二个列表从列表中提取字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下列表:
list1 = [[value1:name1,value2: check1],[value1:name2,value2:check2],
[value1:name3,value2:check3]]
list2 = ['name1','name2']
我想将所有value2
用于 name1
和 name2
。
为:
[check1,check2]
解决方案
这应该做到这一点:
def list3 = list1.findAll {list.value1 in list2} .value2
I have the following lists:
list1 = [["value1":"name1", "value2":"check1"], ["value1":"name2", "value2":" check2"],
["value1":"name3", "value2":" check3"]]
list2 = ['name1', 'name2']
I would like to pull the list of all the "value2"
for name1
and name2
.
as:
[check1, check2]
解决方案
This should do it:
def list3 = list1.findAll { it.value1 in list2 }.value2
这篇关于根据第二个列表从列表中提取字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文