社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

修改python字典的值

the_martian • 5 年前 • 433 次点击  

假设我有这本字典:

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
 
433 次点击  
文章 [ 5 ]  |  最新文章 5 年前