Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary Help
#1
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
Reply
#2
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(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]:
Reply
#4
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))
Reply
#5
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
thanks to all, Worked. :)))))
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020