How to combine two lists into a dictionary

30 views
Skip to first unread message

jettam

unread,
Sep 22, 2017, 9:33:43 PM9/22/17
to Python Programming for Autodesk Maya
I have two lists that I want to combine into a dictionary, one list for keys, and the other for value.  Could someone help me with this. 

for example :

holder=[]
occurences=[]

dict={[key]:[values]}
Message has been deleted

jettam

unread,
Sep 23, 2017, 12:31:07 AM9/23/17
to Python Programming for Autodesk Maya
I thought I figured it out with this :

combine = dict(zip(holder, occurences) )

But I get this error

# Error: 'dict' object is not callable
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
# TypeError: 'dict' object is not callable # 

Justin Israel

unread,
Sep 23, 2017, 12:51:10 AM9/23/17
to Python Programming for Autodesk Maya

Oh. Don't shadow the built in dict() of you plan to use it later. Call your variable something else.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c688dc7a-0763-4af4-9dd7-f352e78a5524%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Anderson

unread,
Sep 23, 2017, 4:13:55 AM9/23/17
to Python Programming for Autodesk Maya
you can do the following.

keys = ['k1', 'k2', 'k3']
data = ['d1', 'd2', 'd3']

newDict = {k:d for k,d in zip(keys, data)}
Reply all
Reply to author
Forward
0 new messages