I have a dictionary containing keys that at the same time the key contains a certain list of integers. I want to built a dict that shows me the values as keys and the values of this new dict would be a list of the previous keys that contained the previous value. For example, I have:
turns
{'Monday_2022_03_14': [25, 17, 2, 32, 43, 40, 23, 7, 19, 16],
'Tuesday_2022_03_15': [33, 10, 16, 31, 25, 22, 43, 41, 21, 28, 3, 30, 29],
'Wednesday_2022_03_16': [19, 27, 40, 3, 9, 2, 14, 21, 44, 17],
'Thursday_2022_03_17': [16, 23, 1, 30, 29, 44, 5, 42, 27, 19],
'Friday_2022_03_18': [6, 17, 2, 29, 27, 41, 44, 5, 40, 42]}
I would like to have, as an example:
{1:['Thursday_2022_03_17'],
2:['Monday_2022_03_14','Wednesday_2022_03_16','Friday_2022_03_18'],
3:['Tuesday_2022_03_15','Wednesday_2022_03_16],
...} #and so on
I tried to implement the next solution on a loop (I found it in Get key by value in dictionary), but then I realized this could work only in dicts with keys of only one value, not lists like mine:
list(turns.keys())[list(turns.values()).index(16)]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_19168/930684082.py in <module>
----> 1 list(turns.keys())[list(turns.values()).index(16)]
ValueError: 16 is not in list
It's ok if you don'y provide a loop solution, I can implement it but I need help in getting the key name by value (like the line above), but focusing on a list instead of a simple value.
Thanks to all.