I want to create a loop to generate a dictionary with for each key 5 lists with each three values. And add edit the last value of list 2 and 3 based on the key of the dictionary and the index of the list (so list 2 and 3).
I tried the following code but get the error message: 'cannot unpack non-iterable int object'
# Create dicitonairy with 6 empty lists
dict_of_lists = dict.fromkeys(range(0,6),[])
for key, value in dict_of_lists:
# Create 5 lists with the list number as the first value
for li in range(5):
dict_of_lists[key] = [li,0,0]
# Edit the last value of list 1 and 2 (index)
for wi in [1,2]:
dict_of_lists[wi][2] = item[wi]*price[key]
What is the best way to create the following output:
{
0:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
1:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
2:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
3:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
4:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
5:[[0,0,0],[1,0,x],[2,0,x],[3,0,0],[4,0,0]]
}
Where x is a value based on the list where it's in (1 to 5) and the key of the dictionary.