Search code examples
pythonsetmappingoperator-keyword

Mapping set operations in python


I have a very simple problem, but today, I confess I have trouble finding the solution: I want to use the '&' operator on python sets, but I don't know how many sets I will have to deal with. Is it possible to use a mapping with python to achieve this?

Thanks !


Solution

  • You can simply use

    set.intersection(*some_list_of_sets)
    

    If you still want to use the operator,

    functools.reduce(operator.and_, some_list_of_sets)