How can I intersect values of a dictionary in python?
Question:
For example this is a dictionary
dic={3: [2, 7, 8], 1: [7]}
I want a list like this [7]
Answers:
First, get all the values using .values
, then convert them to set, and get the intersection of them:
set.intersection(*list(map(set, dic.values())))
For example this is a dictionary
dic={3: [2, 7, 8], 1: [7]}
I want a list like this [7]
First, get all the values using .values
, then convert them to set, and get the intersection of them:
set.intersection(*list(map(set, dic.values())))