Hey Guys, so trying to add keys and values to a dictionary.
The Result that it keeps giving me is just the last pairing of keys and values.
{‘UpperLid_Open’: ‘UpperLid_Open_InBtwn090’}
Shouldn’t it be updating the whole list?
Why is is it only spitting out the last pairing of keys and values?
I am using Maya 2012 with Python version 2.6.4 if that is of any help.
Here is my code
# Select the blendshapes then target
args = cmds.ls(sl=True)
blends = cmds.ls(args[:-1])
# Find all in between blendshapes in the scene
allIBs=cmds.ls('*_InBtwn0*', type ='transform')
#
keys = []
values = []
for blend in blends:
for IB in allIBs:
if blend in IB:
keys.append(blend)
values.append(IB)
dictionary = {}
keysAndValues = zip(keys, values)
for key, value in keysAndValues:
dictionary[key] = value
# Isnt this the same as above??
dictionary = dict(zip(keys, values))
Those should have the same result. Do they not? Are you sure there are more values in the keys and values list. Can you provide a print out of the keys and values
Python dictionaries can only have one entry per key. It looks like you want the value of each blendshape key to be a list.
from collections import defaultdict
# Select the blendshapes then target
args = cmds.ls(sl=True)
blends = cmds.ls(args[:-1])
# Find all in between blendshapes in the scene
allIBs=cmds.ls('*_InBtwn0*', type ='transform')
#
inbetweens = defaultdict(list)
for blend in blends:
for IB in allIBs:
if blend in IB:
inbetweens[blend].append(IB)