Python代码实现小红背单词统计 - 每日打卡记录
{/'title/':/'Python代码实现小红背单词统计 - 每日打卡记录/',/'description/':/'本文介绍如何使用Python代码统计小红背单词的数量,并提供示例代码,帮助你理解如何使用集合来记录已记住的单词。/',/'keywords/':/'小红背单词, Python, 代码, 统计, 集合, 打卡, 小红书/',/'content/':/'///'小红每天都要背单词,然后她会把每天记住了多少单词记录下来,并在小红书上打卡。//n当小红背单词时,如果她已经记住了 i 个单词,且背了一个没有记住的新单词 i +1次,则她就会记住这个新单词。//n例如,当她按顺序背[///' you ///', ///' thank ///', ///' thank ///']时,她第一次背单词///' you ///'时她就能记住///' you ///'。而由于她已经记住了一个单词,所以需要背两次///' thank ///'才能记住///' thank ///'。//n现在你知道了小红背单词的顺序,请你求出小红今天记住了多少个单词。用python编写代码内容:def countWords(words)://n count = 0//n memory = set()//n for word in words://n if word not in memory://n memory.add(word)//n count += 1//n return count//n//nwords = [///'you///', ///'thank///', ///'thank///']//nresult = countWords(words)//nprint(result)//n///
原文地址: https://www.cveoy.top/t/topic/qoQV 著作权归作者所有。请勿转载和采集!