我有以下
group1 = ['R1' , 'R2' , 'R1']
group2 = ['F1 is Car' , 'F2 is bus ' , 'F1 is bike']
我想做点像
group3 = {('R1' : 'F1 is car' , 'R2' : 'F2 is bus' , 'R3' : 'F1 is car'}
然后我想搜索单词F1,它应该给我一些类似
的东西result = {'R1' , 'R3'}
我怎样才能完成这个?
答案 0 :(得分:0)
您可以将2个列表压缩在一起制作字典:
group1 = ['R1' , 'R2' , 'R3']
group2 = ['F1 is Car' , 'F2 is bus ' , 'F1 is bike']
d = dict(zip(group1, group2))
然后,您可以使用理解来找到值:
[k for k, v in d.items() if 'F1' in v]