So for example:
JavaScript
x
19
19
1
a = {}
2
3
4
class Person:
5
def getName(self):
6
return self.name
7
8
def getValue(self):
9
return self.value
10
11
def __init__(self, name, value):
12
self.name = name
13
self.value = value
14
15
16
oject = Animal("foo", 2)
17
a[oject.getName()] = oject.getValue(), oject, oject.getName()
18
valuee = 2
19
How would I look for valuee in the dictionary a? I have looked at other articles but most are unhelpful so I thought to turn to this website. Are there any other details I need to add to this post?
Advertisement
Answer
Your question would be likelier to get helpful answers if you took the trouble to post working code, and if it were clear from the title of your question what you are trying to do. Your title says you want to find a value but your code is assigning a value.
JavaScript
1
18
18
1
class Person:
2
def getName(self):
3
return self.name
4
5
def getValue(self):
6
return self.value
7
8
def __init__(self, name, value):
9
self.name = name
10
self.value = value
11
12
class Animal(Person): #without this your assignment to oject will fail
13
pass
14
15
oject = Animal("foo", 2)
16
a = vars(oject)
17
print(a)
18
Output:
JavaScript
1
2
1
{'name': 'foo', 'value': 2}
2
Now this answer may be not what you meant at all. If not, try editing your question to explain whether you are trying to find values in a dictionary or assign them to a dictionary, ensure that the code you present actually works, and say clearly what output you expect.