python - 在字典中,将值从字符串转换为整数

标签 python string dictionary integer

以下面的例子为例:

'user_stats': {'Blog': '1',
                'Discussions': '2',
                'Followers': '21',
                'Following': '21',
                'Reading': '5'},

我想把它转换成:

'Blog' : 1 , 'Discussion': 2, 'Followers': 21, 'Following': 21, 'Reading': 5

最佳答案

dict_with_ints = dict((k,int(v)) for k,v in dict_with_strs.iteritems())

关于python - 在字典中,将值从字符串转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9224385/

相关文章:

python - Behave 测试框架的测试覆盖工具

python - 如何展平解析树并存储在字符串中以进行进一步的字符串操作python nltk

python - pymunk - 是否有标准方法来为对象设置自定义重力?

python - 如何在Python中为str子代覆盖ord行为?

python - pandas DataFrame 将值作为元组进行字典

Python:从excel中的数据创建字典

python - 使用 python 变量执行 shell 命令

java - 德语大写字母的字符集

c++ - 我的程序出现 abort() 错误,但由于它是程序的加载部分,我无法调试它?

c++ - 为什么 std::map 实现为红黑树?