Python 算法:计算重复背诵单词后记忆的单词数量
def count_words(words): count = 0 remembered = set()
for word in words:
if word not in remembered:
remembered.add(word)
count += 1
return count
words = ['you', 'thank', 'thank'] print(count_words(words)) # 输出:2
原文地址: https://www.cveoy.top/t/topic/qoQW 著作权归作者所有。请勿转载和采集!