프로그래밍/Python
[Python] In dictionary, converting the value from string to integer. Dict에서 value가 숫자형이 아닐때 숫자로 변경
홍반장水_
2022. 2. 14. 15:40
반응형
[Python] In dictionary, converting the value from string to integer.
Dict에서 value가 숫자형이 아닐때 숫자로 변경
Taking this below example :
'user_stats': {'Blog': '1',
'Discussions': '2',
'Followers': '21',
'Following': '21',
'Reading': '5'},
I want to convert it into:
'Blog' : 1 , 'Discussion': 2, 'Followers': 21, 'Following': 21, 'Reading': 5
>>> d = {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21', 'Reading': '5'}
>>> dict((k, int(v)) for k, v in d.iteritems())
{'Blog': 1, 'Discussions': 2, 'Followers': 21, 'Following': 21, 'Reading': 5}
In dictionary, converting the value from string to integer
Taking this below example : 'user_stats': {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21', 'Reading': '5'}, ...
stackoverflow.com
반응형