什么样的'For Loop'是这个吗?

时间:2015-10-08 17:17:21

标签: python loops for-loop

嘿伙计们,我从视频教程中得到了这个代码让我很困惑:

import maya.cmds as mc

def jointHierarchy(topJoint , lastJoint = True):

    jointsLists = mc.listRelatives(topJoint , type = 'joint' , ad = True)
    jointsLists .append (topJoint)
    jointsLists . reversed()

    wholeChane = jointsLists [:]
    if not lastJoint:
        jointsWithoutEnd = [ j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )]

这是什么样的循环

'''
    if not lastJoint:
        jointsWithoutEnd = [ j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )]
'''

我们有这样的结构

j for j in jointsLists if mc.listRelatives( j , type = 'joint' ,c =1 )

我尝试了这段代码并且工作正常

任何帮助

1 个答案:

答案 0 :(得分:1)

这就像:

jointsWithoutEnd=[]
for j in jointsLists:
    if mc.listRelatives(j,type='joint',c=1):
         jointsWithoutEnd.append(j)

编辑:正如RobertB所说,这就是列表理解:https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions 希望有所帮助。

相关问题