"Python算法:计算小红每日记住的单词数量"
可以使用Python编写一个函数来实现这个算法。函数的输入是一个单词列表,输出是小红今天记住的单词数量。
```python
def count_words(words):
remembered_words = set()
count = 0
for word in words:
if word not in remembered_words:
remembered_words.add(word)
count += 1
return count
```
使用这个函数,你可以传入小红背单词的顺序列表,例如`["you", "thank", "thank"]`,然后得到小红今天记住的单词数量。
```python
words = ["you", "thank", "thank"]
result = count_words(words)
print(result) # 输出:2
```
在这个例子中,小红背了3个单词,但是只记住了2个单词。
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。