Populating a Nested Dictionary
问题 I have a long list of nested tuples that I am iterating through and appending in a certain way such that an empty dictionary: dict = {} will be filled like this: dict = {a: {b:1,5,9,2,3}, b: {c:7,4,5,6,2,4}, c: {b:3,13,2,4,2}... } The iteration will check if a nested dictionary exists, and if so, then it will append the value, otherwise, create a nested dictionary. My poor attempt looks something like this: longlist = [(1,(a,b)),(2,(b,c)), (3,(c,b)) ... ] dict = {} for each in longlist: if