Search code examples
pythondictionaryintersection

How can I intersect values of a dictionary in python?


For example this is a dictionary

dic={3: [2, 7, 8], 1: [7]}

I want a list like this [7]


Solution

  • 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())))