Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/66053219/python-unable-to-convert-integer-to-string-jsons-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

for row in data:
    row['code'] = str(row['code'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...