小编J87*_*J87的帖子

如何将字典值转换为浮点数

如何将字典值转换为浮点数

dict1= {'CNN': '0.000002'}

s=dict1.values()
print (s)
print (type(s))
Run Code Online (Sandbox Code Playgroud)

我得到的是:

dict_values(['0.000002'])
<class 'dict_values'> # type, but need it to be float
Run Code Online (Sandbox Code Playgroud)

但是我想要的是float值,如下所示:

 0.000002
 <class 'float'> # needed type
Run Code Online (Sandbox Code Playgroud)

python dictionary python-2.7 python-3.x

6
推荐指数
2
解决办法
8490
查看次数

如何比较两个字典并检查是否有新项目

如何比较两个字典并检查是否有新项目,例如在第二个字典中有CCC,如何比较并获得新变量中的CCC.

dict1 = {'AAA': '0.23444', 'BBB': '0.5343'}
dict2 = {'AAA': '0.34343', 'BBB': '0.3435', 'CCC': '0.53322'}
Run Code Online (Sandbox Code Playgroud)

python dictionary python-2.7 python-3.x

0
推荐指数
1
解决办法
729
查看次数

标签 统计

dictionary ×2

python ×2

python-2.7 ×2

python-3.x ×2