Paa*_*das 15 python string dictionary integer
以下为例:
'user_stats': {'Blog': '1',
'Discussions': '2',
'Followers': '21',
'Following': '21',
'Reading': '5'},
Run Code Online (Sandbox Code Playgroud)
我想将其转换为:
'Blog' : 1 , 'Discussion': 2, 'Followers': 21, 'Following': 21, 'Reading': 5
Run Code Online (Sandbox Code Playgroud)
Amb*_*ber 16
dict_with_ints = dict((k,int(v)) for k,v in dict_with_strs.iteritems())
Run Code Online (Sandbox Code Playgroud)
jco*_*ado 13
您可以使用字典理解:
{k:int(v) for k, v in d.iteritems()}
Run Code Online (Sandbox Code Playgroud)
d带字符串的字典在哪里.