list =[‘列表1’,‘列表2’,‘列表3’……‘‘列表N’],如何对这个列表中的N个列表元素求交集
>>> from functools import reduce
>>> L = ['列表1', '列表2', '列表3']
>>> reduce(lambda x,y : set(x) & set(y), L)
{'表', '列'}
In [1]: L = [[1,2,3,4], [2,3,4,5], [3,4,5,6],[1,2,3,4,5,6]]
In [2]: set(L[0]).intersection(*L[1:])
Out[2]: {3, 4}
- maya获取多个物体首个公共父物体
from functools import reduce
import pymel.core as pm
sel = pm.ls(sl=1)
def get_own_parent(*objs):
all_parent = []
for i in objs:
parent = i.getAllParents()
all_parent.append(parent)
own_parents = reduce(lambda x,y : set(x) & set(y), allParent)
own_parent = sorted(own_parents, key=lambda x:len(x.longName()))[-1].shortName()
return own_parent