Python中文
首页
教程
问答
标签
搜索
登录
注册
在列表理解中如何将字典值转换成小写?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一份字典清单</p> <pre><code>list_dict = [{'name':'Rita' , 'customer_id': 'A12B1', 'city': 'Chennai'}, {'name':'Sita' , 'customer_id': 'A61B8', 'city': 'Salem'}] </code></pre> <p>我需要得到结果</p> <pre><code>list_dict = [{'name':'rita' , 'customer_id': 'a12b1', 'city': 'chennai'}, {'name':'sita' , 'customer_id': 'a61b8', 'city': 'salem'}] </code></pre> <p>我试过了</p> <pre><code>new_list = [] for index in range(len(list_dict)): new_dict = {} for key,val in list_dict[index].items(): new_dict[key] = str(val).lower() new_list.append(new_dict) </code></pre> <p>如何使用列表理解获得相同的结果?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我想这会解决你的问题:</p> <pre><code>[{ key: str(value).lower() for key, value in e.items() } for e in list_dict ] </code></pre> <p>基本上,你必须使用包含听写理解的列表理解。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python闭包能否存储和更改外部标量?
8 回答
python闭包行为怪异
2 回答
python闭包问题源代码编译器
4 回答
Python问gam
6 回答
Python问答游戏逻辑E
7 回答
Python问答程序。你能帮我找出哪里出了问题吗?谢谢
6 回答
Python问答程序问题与分数
2 回答
Python问题
7 回答
Python问题 | 在https://www.testdome.com开发的代码测试分数有bug吗
4 回答
Python问题,上载文件的名称和缩略图
9 回答
python问题,将img的相对url连接到绝对url
8 回答
Python问题,机械化机器人
7 回答
Python问题,用不同的模板发送大量电子邮件?
10 回答
Python问题,类型错误:“float对象不能解释为integer”。无法在“for”循环中返回函数的值
5 回答
Python问题:“overflowerr:Python int太大,无法转换为C long”
5 回答
Python问题:“空数据帧的绑定方法NDFrame.head”
3 回答
Python问题:AttributeError:'_io.TextIOWrapper'对象没有属性'split'
10 回答
Python问题:AttributeError:'dict'对象没有'upper'属性
6 回答
Python问题:CS圆7C循环,正方形普查
1 回答
Python问题:ODE系统的参数估计,例如系数是函数
8 回答