简体   繁体   中英

Python convert value from int to string into array dictionary

i have a specific array dictionary that have a specific int value. This is an example:

res = [{'number': 2, 'm': '13520'}, {'number': 17, 'm': '13518'}]

how i can convert the value of number key, from int to string? Thanks

A simple loop will work for in place modification:

res = [{'number': 2, 'm': '13520'}, {'number': 17, 'm': '13518'}]

for d in res:
    if 'number' in d:
        d['number'] = str(d['number'])

output:

[{'number': '2', 'm': '13520'}, {'number': '17', 'm': '13518'}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM