【发布时间】:2019-05-21 21:23:33
【问题描述】:
我是 python 新手,正在尝试将许多字符串的大小写更改为小写。
许多字符串作为列表的元素包含,列表本身是字典的键(字符串数据类型)的值。
这是字典:
{
'1000268201_693b08cb0e' : ['A child in a pink dress is climbing up a set of stairs in an entry way .', 'A girl going into a wooden building .', 'A little girl climbing into a wooden playhouse .', 'A little girl climbing the stairs to her playhouse .', 'A little girl in a pink dress going into a wooden cabin .'],
'101654506_8eb26cfb60' : ['A brown and white dog is running through the snow .', 'A dog is running in the snow', 'A dog running through snow .', 'a white and brown dog is running through a snow covered field .', 'The white and brown dog is running over the surface of the snow .']
}
我为上述字典编写的代码,键为1000268201_693b08cb0e 和101654506_8eb26cfb60,作为句子列表的值是:
for i in mapping:
for j in range(0,len(mapping[i])):
mapping[i][j]=mapping[i][j].lower();
什么是完成上述工作的有效而简洁的方法?
【问题讨论】:
-
它适用于我:ideone.com/g1m5A2
-
@Drako 真的?????
-
@Drako 这在很多层面上听起来都是错误的,其中最重要的是
97-65 != 22 -
是的,你的代码没问题。为什么你认为它不起作用?
-
@AnthonyGeoghegan 我希望,现在,问题在编辑后得到了明确的定义!
标签: python list dictionary lowercase