I have a file with multiple dictionaries, one in each line. They all have the same keys. I want to rename one key from 'id' to 'orderid' in all of them. What is the most efficient way to do so?
Sample data:
{'total_ex_tax': '11.0000', 'is_deleted': False, 'status_id': 5, 'id': 614534}
{'total_ex_tax': '100.0000', 'is_deleted': False, 'status_id': 5, 'id': 614535}
Code so far:
def popAndMergeDicts(dicts):
dictLine = ast.literal_eval(dicts)
tempDict = dictLine['billing_address']
del dictLine['billing_address']
for i in tempDict:
dictLine[i] = tempDict[i]
# insertOrdersInDatabase(dictLine)
rename_id(dictLine)
return dictLine
def rename_id(dictionary):
pass
def process_orders_file(filename):
lines = tuple(open(filename))
for line in lines[0:]:
popAndMergeDicts(line)
process_orders_file('allOrdersData')