【发布时间】:2019-02-28 02:36:51
【问题描述】:
你好,
我的目标是使用.lower() 将文本数据中的每个字符串转换为小写。我尝试将.count() 与单行迭代一起使用。但是,我收到以下错误:
TypeError: 'int' object is not iterable
这是我的代码:
# Iterating over the strings in the data. The data is called text
text_lowercase = ''.join((string.lower().strip() for string in text.count(0,)))
我想使用单线迭代并执行此操作。 帮助将不胜感激。干杯!
【问题讨论】:
-
text.count()听起来像一个数字,那么for string in text.count(0,)应该做什么?显然for string in 10之类的东西没有意义,但这就是你正在做的事情。 -
什么是文本?一个字符串?字符串列表?字典?
-
我正在尝试使用 count 作为计数器来遍历 '
text数据 @JohnColeman 中的每个字符串实例 -
@RayToal
text是字符串数据 -
那为什么不直接
text.lower()??? ;-)
标签: python string loops text iteration