'How to initialize a dictionary of dictionary from a list and another dictionary
I have a list that holds x values called "states" which I use to initialize a dictionary.
states_trans_prob = {states.index(s): {0: [], 1:[], 3:[], 4:[], 5:[], 6:[], 7:[], 8:[], 9:[]} for s in states}
As shown, the inner dictionary has 9 keys. I have another dictionary, called "actions" that has the same number of keys, therefore how can I intialize the dictionary instead of specifying it as shown above?
Solution 1:[1]
states_trans_prob = {states.index(s): {key: [] for key in actions.keys()} for s in states}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | krm76 |
