Python Code To Find All Persons Based On Qty Of Books Sold
Hi, i got stuck with the below code, while I was trying to find solution for the question: Find all persons based on quantity of books sold. below is the content of the file 1711.
Solution 1:
Sounds like you want some nested dictionaries. The top level one should have keys that are all the names, and the values should be another dictionary.
Those dictionaries should have keys of the items, and the value should be another dictionary.
Finally, those dictionaries should have keys that have the store, and the values should be the number that have been sold to that store.
So then if you go: sales_dict["david"]["book"]["target"] it will spit out 10 for you.
edit: Here's the gist of creating the dictionary. I think you should probably refer to https://docs.python.org/3/tutorial/datastructures.html#dictionaries if you are still having issues.
d = {}
for line in f:
a=line.split()
l,m,n,o=str(a[0]), str(a[1]), int(a[2]), str(a[3])
if l notin d:
d[l] = {}
if m notin d[l]:
d[l][m] = {}
if n notin d[l][m]:
d[l][m][n] = 0
d[l][m][n] += int(o)
Post a Comment for "Python Code To Find All Persons Based On Qty Of Books Sold"