2017-08-04 351 views
-3

這是一個瑪雅Python問題。兩個列表在Python中交互

enter image description here

如何創建一個for循環,使這個

enter image description here

創建兩個列表,一個緩衝區,一個用於MM。 使用此命令,cmds.connectAttr(MM + 'messeage',緩衝區+」。renderPass',F = TRUE)

您可以連接MM緩衝

enter image description here

這是我目前的有:

import maya.cmds as cmds 
import maya.mel as mel 
import random as rand 
import math 

bufferls=[] 
MMls=[] 



for i in range(5): 

    writeToColor=mel.eval('mrCreateCustomNode -asUtility "" writeToColorBuffer;') 
    cmds.rename(writeToColor, 'buffer'+str(i))  
    bufferls.append('buffer'+str(i)) 

for i in range(2): 
    MutiMatte = cmds.createNode('renderPass', name=('MM'+str(i)))   
    cmds.setRenderPassType('MM'+str(i),type='CSTCOL') 
    MMls.append(MutiMatte) 



def n_split(bufferls, n=3): 
    num_extra = len(bufferls) % n 
    zipped = zip(*[iter(bufferls)] * n) 
    return zipped if not num_extra else zipped + [bufferls[-num_extra:], ] 


for buffer in n_split(bufferls, 3): 
    newlists =list(buffer) 
    print newlists 

回答

0

您可以通過使用listA枚舉迭代,然後使用切片從listB得到位:

def pair_in_groups(listA, listB, n): 
    for i, item in enumerate(listA): 
     yield (item, listB[n*i: n*(i+1)]) 

listA = ['mm0', 'mm1', 'mm2'] 
listB = ['aa1', 'aa2', 'aa3','aa4','aa5'] 

for pair in pair_in_groups(listA, listB, 3): 
    print(pair) 

打印

('mm0', ['aa1', 'aa2', 'aa3']) 
('mm1', ['aa4', 'aa5']) 
('mm2', [])