Structure is as follows:
{"A": [{
"A": "",
"B": "2",
"C": "3QWE",
"D": 1800,
"E": null,
"F": null
},
{
"A": "",
"B": "2",
"C": "XYT17",
"D": 1800,
"E": "3, 1*",
"F": null
},
{
"A": "",
"B": "N8HTY",
"C": "XYT17",
"D": 1800,
"E": "7,6,(5)**",
"F": null
},
{
"A": "",
"B": "1AJ21",
"C": "XYT17",
"D": 1800,
"E": "7,6,5",
"F": null
}
],
"B": [{
"A": "",
"B": "LS231",
"C": "XYT17",
"D": 1800,
"E": "1,2,3",
"F": null
},
{
"A": "",
"B": "22GHE",
"C": "XYT17",
"D": 1800,
"E": "3, 1*",
"F": null
}
]
}
I want the '*' and '(' and ')' to be removed from the value of the key 'E' if it is present The output should be as follows for "E"
i.e. "E":"7,6,(5)**" ---> "E":"7,6,5"
"E":"3, 1*" ---> "E":"3,1"
"E":"1,2,3" stays the same
Also if after processing "1*" i have the final output as only one digit say "1" then how can i convert it to integer before updating the value.
What i did was
x=copy.copy(item['E'])
for char in '*':
x = x.replace(char,'')
item['E']=x
This gets me the result as a string. Now if i want it to be stored as an integer value if there is only a single digit then what should be done? I tried
item['E'] = int(x)
to get ValueError: invalid literal for int() with base 10: ''
Thanks in advance