How to find elements that are common to all lists in a nested list?

后端 未结 4 2045
孤城傲影
孤城傲影 2020-12-21 12:37

I have a large nested list and each list within the nested list contains a list of numbers that are formatted as floats. However every individual list in the nested list is

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 12:50

    Try this, it's the simplest solution:

    set.intersection(*map(set, nested_list))
    

    Or if you prefer to use generator expressions, which should be a more efficient solution in terms of memory usage:

    set.intersection(*(set(e) for e in nested_list))
    

提交回复
热议问题