{'Sensor': ['Data 0', 'Data 1'], 'Microphone': ['Microphone']}
is my dictionary.From Data 0
I need to access Sensor
.
Asked
Active
Viewed 157 times
2

Sociopath
- 13,068
- 19
- 47
- 75

nagashree Upadhya
- 31
- 3
-
1Possible duplicate of [How to get the key from value in a dictionary in Python?](https://stackoverflow.com/questions/45635242/how-to-get-the-key-from-value-in-a-dictionary-in-python) – m13op22 Apr 04 '19 at 04:47
-
@HS-nebula In that question there are only one string value per key, so not exactly duplicate – Sociopath Apr 04 '19 at 04:48
-
Add some more information in the question. Write your required output in the Question. – Smack Alpha Apr 04 '19 at 04:54
1 Answers
0
Use list-comprehension
to iterate over dict and check if Data 0
is in values(which is list):
a = {'Sensor': ['Data 0', 'Data 1'], 'Microphone': ['Microphone']}
print([k for k,v in a.items() if 'Data 0' in v][0])
Output:
'Sensor'

Sociopath
- 13,068
- 19
- 47
- 75