[ACCEPTED]-Iterating through THREE lists at once in Python?-maya

Accepted answer
Score: 32

I do not quite understand the question, are 7 you looking for

import itertools
for a, b, c in itertools.izip(lst1, lst2, lst3):
    ...

?

What izip does is it takes a 6 variable number of arguments and returns 5 an iterator that always yields the respective 4 items of the arguments (a tuple of the first 3 arguments in the first run, a tuple of the 2 second arguments in the second run, and 1 so on and so forth).

Score: 2

Python3 answer:

for a, b, c in zip(lst1, lst2, lst3):
    ...

0

Score: 1

Why are there "There are three different 8 lists all of the same object TYPE"? Why 7 can't this be fixed to create one list, where 6 all three objects are matched correctly?

Odds 5 are good that a simple mapping would be 4 better than three parallel lists.

Specifically, you 3 need to fix chHipIK = cmds.listRelatives(IKJoint, ad = True, type = 'joint') to work like this.

chHipIK = [ { 'IK': ik } for ik in mds.listRelatives(IKJoint, ad = True, type = 'joint') ]
for i, fk in enumerate(cmds.listRelatives(FKJoint, ad = True, type = 'joint')):
    chHipIK[i]['FK']= fk
for i, bind in enumerate(cmds.listRelatives(bindJoint, ad = True, type = 'joint')):
    chHipIK[i]['FK']= bind

So 2 that chHipIK is a list of mappings that has all 1 three pieces of information.

Score: 1

@florian mayer way with zip or izip works 2 really fine, but you can also use the enumerate 1 to get the list count,

list_a  = ["x", "y"]
list_b  = ["k", "j"]
list_c  = ["m", "n"]

for count, item in enumerate(list_a):
    print item, list_b[count], list_c[count]

More Related questions