In python, trying to convert the key-value pair from integer to string.
Input:
data = [
{'code': 123456, 'value': 32},
{'code': 987654, 'value': 12}
]
Expected Output
data = [
{'code': '123456', 'value': 32},
{'code': '987654', 'value': 12}
]
Trying for code-value.
Here's a dictionary comprehension inside a list comprehension to achieve this:
where
new_datawill hold the data in your desired format as:Inside the dictionary comprehension I am checking whether the key is
'code', and type-casting the value tostrin case of a match.