我正在写一个程序来审查一些单词。在
def censor(sentence, word):
splitted_sentence = sentence.split() #splitted_sent = ["he", "is", "a", "clucking", "boy"]
censored = [item.replace(item, "*" * len(item) for item in word)]
return censored
print censor("he is a clucking boy", "clucking")
在这个例子中,我想做的是过滤句子中的单词“clucking”。但当我运行它时,它说:
Generator expression must be parenthesized if not sole argument.
不需要列表理解来使简单的事情复杂化东西。拜托找到下面的简单代码做同样的事情。在
可能你把括号放错地方了。试试这个:
相关问题 更多 >
编程相关推荐