I have a list of dictionaries, where the key and values are both strings.
However, I want to convert the value from a string to a int.
I have tried multiple ways but nothing seems to be working, either I receive 'key error: '1' or 'size of dictionary has changed'.
My dictionary looks like this (I have total 54 dictionaries)
{'1A': '1',
'3E': '2',
'PRODUCT NUMBER': '1',
'Week': '1'},
{'1A': '1',
'1B': '1',
'1C': '1',
'1D': '2',
'1E': '2',
'2C': '1',
'3E': '2',
'PRODUCT NUMBER': '2',
'Week': '1'},
and so on.
My code:
import csv
import pprint
from typing import List, Dict
input_file_1 = csv.DictReader(open("DATA CWK SHOPPING DATA WEEK 1 FILE B.xlsb.csv"))
table = list(input_file_1)
buyers = []
for row in table:
buyers_list = {}
for i in row:
if row[i] != '' and i != 'PRODUCT NAME':
buyers_list.update({i : row[i]})
buyers.append(buyers_list)
pprint.pprint(buyers)
question from:
https://stackoverflow.com/questions/65943955/convert-value-in-dictionaries-from-a-list-of-dictionaries-from-a-string-to-integ 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…