我如何对列表进行排序python maya

时间:2018-10-24 17:20:09

标签: python list sorting filter maya

我有一个列表[0,0,0,0.5,0.5],我想对其进行排序以仅保留不等于0的值。

from maya import cmds

def splitShape():
    a = cmds.ls(sl=True)

    if len(a)<=1:
        cmds.warning( "Select 2 target")

    elif len(a) >= 2:
        #cmds.warning( "SPLIIIIIT")
        cmds.select( a[0] , r = True)
        Vertex = a[0] + '.vtx[*]'
        cmds.select(Vertex)

        #_____LIST______
        b = cmds.getAttr(a[0] + 'Shape' + '.pnts[*]' + '.pntz')
        #print b

        if len(b) == 0:
            print ok
        elif len(b) != 0:
            cmds.setAttr( a[0] + 'Shape' + '.pnts[*]' + '.pntz' , 0)

坦克:)

2 个答案:

答案 0 :(得分:0)

要过滤仅保留不等于零的值的列表:

a = [0, 0, 0, 0.5 ,0.5]
list(filter(lambda x: x != 0, a))
# [0.5, 0.5]

答案 1 :(得分:-1)

a = [0, 0, 0, 0.5 ,0.5]

b = [x for x in a if a != 0] # list comprehension