我有一个循环给我三个变量matteGroupmatteNameobject我想创建一个嵌套的diciary来保存所有的数据,比如:dictionary{matteGroup: {matteName: obj1, obj2, ob3} }我逐一检查对象,所以我想创建matteGroup如果它不存在,如果不使用Exxxt,则创建,然后创建或追加对象的名称。我尝试了很多解决方案,如普通字典、DefaultDict和一些我在网上找到的自定义类,但是我没有能够正确地做到这一点。我有一个很好的嵌套,我不能附加,或反之亦然。这是循环 dizGroup = {} dizName = {} 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] = list() dizGroup[matteGroup].append(matteName) if matteName not in dizName: dizName[matteName] = list() dizName[matteName].append(obj)有了这个,我把这两本词典分开了,但没那么有用!有什么暗示吗?谢谢 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 试试这样的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) (adsbygoogle = window.adsbygoogle || []).push({});
09-12 07:50