How to make a nested dictionary and dynamically append data

前端 未结 5 1141
闹比i
闹比i 2021-01-13 02:16

I have a loop giving me three variables

matteGroup
matteName
object

I would like to make a nested dicionary holding all the data like:

5条回答
  •  灰色年华
    2021-01-13 02:30

    try something like this

    dizGroup = {}
    
    for obj in mc.ls(type='transform'):
        if mc.objExists(obj + ('.matteGroup')):
            matteGroup = mc.getAttr(obj + ('.matteGroup'))
            matteName = mc.getAttr(obj + ('.matteName'))
    
            if matteGroup not in dizGroup:
                dizGroup[matteGroup] = {}
    
            if matteName not in dizGroup[matteGroup]:
                dizGroup[matteGroup][matteName] = []
    
            dizGroup[matteGroup][matteName].append(obj)
    

提交回复
热议问题