【发布时间】:2020-07-31 21:23:01
【问题描述】:
- 需要创建一个接受字符串的函数
例如“你好,今天天气很好,很热”
- 该函数需要使用字符串中单词的LIST,并创建一个由字符串中的单词组成的SET。
输出应该是:(“hello”“it”“is”“a”“nice”“day”“today”“and”“hot”) 注意:该集合只有句子中唯一的单词,没有重复的单词
我自己试过了,但它说错了:
opening_line="It was the best of times, it was the worst of times"
def get_vocabulary(word_list):
words = word_list.split()
dickens_words = set()
dickens_words.add(words)
return words
print(get_vocabulary(opening_line))
【问题讨论】:
-
如果你使用
append而不是add呢? -
使用
update代替add并返回dickens_words