we can pass a dictionary like a normal variable being passed like:
and the function on the other end will receive the variable and can be used like this :
to Display the contents of dictionary we can then use the for loop, in the above example although we do not need to use campath.keys() but I have used it for some specific reason where it is used in the actual program.
You have also noticed the enumerate function, this comes handy when you want to use the indexing of number of elements
here when I am printing inside the for loop I first have index to see what is the Zeroth elemetn then I use the same index to select the first key and display it, since even in dictionary like in list first item starts from 0, taking advantage of enumerator function I can print each of the key
in my above example the key is camera shape nodes
if I have to display the paths of each camera shape node i.e. its values I would do it like this:
- print(index, campath.values()[index]
You may read more about dictionary in Python Documentation
So in the above article I covered:
- Python Dictionary,
- how to pass them to a function
- using enumerator function
I came up with this learning while I was working on my first personal project in python with Maya. And thought it to post to blog and share the learning!!
I have used simplest explanation possible, I hope you like and understood , dictionaries are very useful. write below in the comments if you want to learn more or ask any question..