Replace re.split with regular split to get the same result (you can use the json library and the loads function) The code: f = open('purchase_log.txt', encoding='utf-8') import re purchases = {} for i, line in enumerate(f): line = re.split(r",|:", line.strip()) keys = line[1] values = line[3] purchases[keys] = values
def split_func(a): import json import re a = json.loads(a.strip()) purchases = {} for i, line in enumerate(a): line = re.split(r",|:", str(line)) keys = line[1] values = line[3] purchases[keys] = values return purchases split_func(a)