Reputation: 347
Please post any suggestions that I can do, please do not post any code.
Test = [1, 2, 3]
DTest = {'a':[], 'b':[]. 'c':[]}
I want to write some code so that each element in Test is placed into the empty lists in DTest so that it looks like this: (assuming Test and DTest is always the same length)
DTest = {'a':[1], 'b':[2], 'c':[3]}
I was thinking that I should use a nested "for" loop, but I end up with this:
DTest = {'a':[1, 2, 3], 'b':[1, 2, 3], 'c':[1, 2, 3]}
Please don't post any code, only suggestions on what I can do. Thanks
Upvotes: 0
Views: 70
Reputation: 1788
This code is not tested it is just an idea to build a dictionary.
testVal = Test.get(i) //Get items from List
for j in list(DTest.keys()): // Get Keys from Dictionary
DTest[j] = testVal // Update Dictionary values.
Hope It may helps :)
Upvotes: 0
Reputation: 11396
zip Test and DTest and use dict comprehensions to get it in the form that you want.
respecting your request not to show code. let me know if you decide otherwise
Upvotes: 1