Generation

generate functionSun, 18 Dec 2022

Rewrite the code with a command that removes unnecessary quotation marks (' ') in the dictionary: Here's the problem: Output: {' "user_id"': ' "category"}', ' "1840e0b9d4"': ' "Products"}', How it should be: Output: {"user_id": "category"}, "1840e0b9d4": "Products"}, The code: f = open('purchase_log.txt', encoding='utf-8') import re import json purchases = {} for i, line in enumerate(f): line = re.split(r",|:", line.strip()) keys = line[1] values = line[3] purchases[keys] = values

f = open('purchase_log.txt', encoding='utf-8') purchases = {} for i, line in enumerate(f): line = re.split(r",|:", line.strip()) keys = line[1].strip('"') values = line[3].strip('"') purchases[keys] = values

Questions about programming?Chat with your personal AI assistant