【发布时间】:2019-02-27 22:59:41
【问题描述】:
早安,
我的目标是创建一个函数,接收作为字符串的文本data,并将其转换为小写字母。我希望稍后通过传入数据来应用该函数。
但是,当我调用/应用该函数并尝试在其中传递数据时,我不断输出此错误。
TypeError: 'generator' 对象不可调用
我做了一些进一步的研究,我只是好奇映射是否会导致这个问题?
有没有什么办法可以使功能以最有效的方式工作。
下面是我的代码:
def preprocess_text(text):
""" The function takes a parameter which is a string.
The function should then return the processed text
"""
# Iterating over each case in the data and lower casing the text
edit_text = ''.join(map(((t.lower().strip()) for t in text), text))
return edit_text
然后测试功能看是否有效:
# test function by passing in data.
""" This is when then the error occurs!"""
text_processed = preprocess_text(data)
非常感谢帮助我了解问题所在以及正确的解决方法。 提前干杯!
【问题讨论】:
标签: python string loops nlp iteration