Python Forum

Full Version: Dictionary Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi guys  


mydict = {'transform':[4,52,6.3] , 'rotation':[77,89,12] , 'scale':[44,55,96]}


mydict['scale']
Output:
[44,55,96]
how i can access the list index, for example only access 55 or 96, no all items!   Think

i learn python for CG & VFX , i need to define (for example) 'scale' [x,y,z] , how i can access to x or y or z, in dictionary.   Think
The same way you access a list items. 
In [1]: mydict = {'transform':[4,52,6.3] , 'rotation':[77,89,12] , 'scale':[44,55,96]}

In [2]: mydict['scale'][2]
Out[2]: 96

(Dec-20-2016, 07:43 PM)wavic Wrote: [ -> ]The same way you access a list items. 
In [1]: mydict = {'transform':[4,52,6.3] , 'rotation':[77,89,12] , 'scale':[44,55,96]}

In [2]: mydict['scale'][2]
Out[2]: 96


thankyou
what is:  in & out ???   Huh
in[1]  ,  out[2]     Think
in[1]:
in[2]:
out[2]:
To get the value:
z = mydict['scale'][2]
print(z)
To see if the value is in any dict entry:
mydict = {
    'transform': [4, 52, 6.3],
    'rotation' : [77, 89, 12],
    'scale': [44, 55, 96]
}

for key, value in mydict.items():
    if 96 in value:
        print('found 96 in: {}'.format(key))
It's just a Python interpreter prompt. Like '>>>' in the usual Python interpreter. It's called IPython and it's awesome. 
See this: https://www.youtube.com/watch?v=vrdYvjGTrQA
thanks to all, Worked. :)))))