I have the following list
object(it's not a dictionary yet). The list
contains a name and the products and the quantity they carry which is huge but I only put 3 samples:
file = open('.txt')
rdr = file.read()
prod_lists = rdr.split('\n')
so the prod_lists are as follows:
prod_lists = {'allen':{'tv':100,'playstation':200,'xbox':30},
'balden':{'tv':200,'laptop':300},
'cathy':{'watch':100,'printer':200}}
How would I split the above list
into a (key, value)
dictionary? also, how would I find sum
of products for each individual. Here's what I tried to do which is not working:
prod_dict = dict((k.split(),v.split()) for k,v in (i.split('{')for i in prod_lists))
for key,value in prod_dict.items():
print(key,value)