Reputation:
this is probably a stupid question but : I have this code which worked fine, until I tried to add ml. I tried several manners but
init_dict = []
with open("example.csv", "r") as new_data:
reader = csv.reader(new_data, delimiter=',', quotechar='"')
for row in reader:
if row:
columns = [row[0], row[1], row[3]]
init_dict.append(columns)
result = defaultdict(list)
for ean, price, ml in init_dict:
result[ean].append(price)
result[ean].append(ml)
for ean, price, ml in result.items():
print(ean, " // " . join(price), "::". join(ml))
I need to add the ml info to my current output which is like :
676543 : 6,7 // 6,7
786543 : 3
4543257 : 7,8 // 9,0
etc... Thank you for your help
Upvotes: 1
Views: 110
Reputation: 106768
Your result
variable is a dict of lists of two items, so you should unpack its items like this instead:
for ean, (price, ml) in result.items():
Upvotes: 1