Py学习  »  Python

修改python字典的值

the_martian • 5 年前 • 427 次点击  

假设我有这本字典:

my_dicts =  {'key1': 'true', 'key2': 'true'}

我想用 True

我怎么能做到。

我试过这样做:

for t in my_dicts:
    t.update((k, "True") for k, v in t.items() if v == "true")

但我得到这个错误:

AttributeError: 'str' object has no attribute 'update'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30324
 
427 次点击  
文章 [ 5 ]  |  最新文章 5 年前