Find all values in a list which match in a dictionary?

Viewed 53

lets say I have the following dictionary

dict1= {"a":[1,2,3],"b":[2,3,4]}

how would I make it so the output is:

[2,3]

where the values match in a dictionary.

1 Answers

you can refer to my code bellow:

arr1 = d['a']
arr2 = d['b']
arrResult = []
for i in arr1:
  if i in arr2:
    arrResult.append(i)
print(arrResult)

and here is the result: [2, 3]

More advanced you can use:

x = set.intersection(*map(set, d.values()))    
print(x)
Related