python - 小写列表列表

标签 python string list nested lowercase

我有一个列表列表:

data = [['SiteUrl','Url','Title'],['SiteUrl','Url','Title']]

如何使用 python 遍历列表并将所有内容小写?

最佳答案

使用列表理解:

data = [[x.casefold() for x in sublst] for sublst in data]

或者功能上:

data = [list(map(str.casefold, x)) for x in data]

来自 the docs :

Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string.

关于python - 小写列表列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54438770/

相关文章:

python - 优化代码以检查列表元素是否唯一

python - Unresolved reference 'build' - YouTube Python API

python - 如何按字典中的值对字典列表进行排序?

c++ - 构造函数初始化列表中的函数?

list - 具有任意数量生成器的 Haskell 列表理解

r - 测试列表的所有元素(列表本身)是否相等

python - PEP-492 中的协同程序会绕过 Python 3.5 中的 GIL 吗?

c - scanf() 对包含多个单词的字符串的行为

c++ - 在 C++ 中按空格拆分字符串的最快方法

java - 关于双数据类型