我有一个字典列表如下:
I have a list of dictionaries as follows:
list = [ { 'a':'1' , 'b':'2' , 'c':'3' }, { 'd':'4' , 'e':'5' , 'f':'6' } ]
如何将列表中每个字典的值转换为 int/float?
How do I convert the values of each dictionary inside the list to int/float?
这样就变成了:
list = [ { 'a':1 , 'b':2 , 'c':3 }, { 'd':4 , 'e':5 , 'f':6 } ]
谢谢.
for sub in the_list:
for key in sub:
sub[key] = int(sub[key])
将其转换为 int 而不是字符串.
Gives it a casting as an int instead of as a string.
这篇关于如何将字典中的字符串值转换为 int/float 数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!