Alireza Soleimanikhah
Alireza Soleimanikhah

Reputation: 21

what kind of 'For Loop' is this?

hey guys i have this code from a video tutorial that confused me :

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 )]

what kind of loop is this

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

do we have any structure like this

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

i tried this code and it worked correctly

any help

Upvotes: 0

Views: 70

Answers (1)

aban-developer
aban-developer

Reputation: 78

This is just like:

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

EDIT: As RobertB said, that is list comprehension : https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions Hope that helps.

Upvotes: 1

Related Questions