Hey guys!
I have a question about dictionaries, namely how I can create a nested dictionary from a loop.
The problem is as follows. I have a farm and several clients buying fruit and vegetables from me.
Smith Apple 100
Davis Apple 70
Smith Potato 40
Smith Apple 10
Brown Cucumber 30
Davis Cucumber 90
Miller Potato 50
Brown Potato 30
Brown Potato 50
Davis Apple 30
Miller Cucumber 40
The first column is the name of the client. The second one is the type of product he/she buys. The third one is the number of sold kilograms.
Here, I have to create a nested dictionary using the data above. The output should be like this:
The best I could get so far is to create a dictionary with names as key. I think when I at least know how to create a value in the form of a dictionary I can try further.
Thank you in advance!
I have a question about dictionaries, namely how I can create a nested dictionary from a loop.
The problem is as follows. I have a farm and several clients buying fruit and vegetables from me.
Smith Apple 100
Davis Apple 70
Smith Potato 40
Smith Apple 10
Brown Cucumber 30
Davis Cucumber 90
Miller Potato 50
Brown Potato 30
Brown Potato 50
Davis Apple 30
Miller Cucumber 40
The first column is the name of the client. The second one is the type of product he/she buys. The third one is the number of sold kilograms.
Here, I have to create a nested dictionary using the data above. The output should be like this:
{'Smith': {'Apple': 110, 'Potato': 40}, 'Davis': {'Apple': 100, 'Cucumber': 90}, Brown: {'Cucumber': 30, 'Potato': 80}, Miller: {'Potato': 50, 'Cucumber': 40}}I've been trying to crack this problem for two days


Thank you in advance!