Edit nested dictionary with limited information
Posted
by
user1082764
on Stack Overflow
See other posts from Stack Overflow
or by user1082764
Published on 2012-05-30T22:38:15Z
Indexed on
2012/05/30
22:40 UTC
Read the original article
Hit count: 532
python
|dictionary
How can i change the 'space' of 'albert' if i dont know if he is a donkey or a zebra?
self.object_attr = {'donkey': {
'name': 'roger', 'zone': 'forrest', 'space': [0, 0]}{
'name': 'albert', 'zone': 'forrest', 'space': [1, 1]}
'zebra': {
'name': 'roger', 'zone': 'forrest', 'space': [0, 0]}{
'name': 'albert', 'zone': 'forrest', 'space': [1, 1]}}
This can search for albert in the dictionary but how can i change his location?
for i in self.object_attr
for j in self.object_attr[x][name]
if j == 'albert'
© Stack Overflow or respective owner