百科问答小站 logo
百科问答小站 font logo



Python中有什么方法能将一段英文里的不重复单词挑出来? 第1页

  

user avatar   PandoraEartha 网友的相关建议: 
      

       string='the tree turn green and green' words=string.split() wordsCount={} for word in words:     wordsCount[word]=wordsCount.get(word,0)+1 for wordsCounted in wordsCount.keys():     if wordsCount[wordsCounted]==1:         print(wordsCounted)     


user avatar    网友的相关建议: 
      
       def _pick_words(s: str):     from collections import Counter     words = s.split()     result = Counter(words)     return [w for w, t in result.items() if t == 1]     


       def _pick_words(s: str):     result = {}     words = s.split()     for word in words:         times = result.get(word, 0)         result[word] = times + 1     return [w for w, t in result.items() if t == 1]     




  

相关话题

  如何理解“from xxx import *这种写法会给你带来无穷无尽的噩梦?”? 
  如何零基础入门 Python? 
  自学 Python 之后如果不去公司上班,自己一个人可以通过此技能挣什么钱? 
  如何学习Python,以及新手如何入门? 
  Python 怎么二次封装一个系统函数? 
  为什么很多人都说 Python 简单? 
  python中用isdigit函数判断是否为数字,但当输入为负数是不行?怎么解决? 
  SQL和Python 哪个更容易自学? 
  为什么有些编程语言的数组要从零开始算? 
  学python在老师全用mac的情况下有必要换成mac吗? 

前一个讨论
为什么《原神》会有大佬帮忙做任务?
下一个讨论
家人们,帮我看看这个极限?





© 2025-06-05 - tinynew.org. All Rights Reserved.
© 2025-06-05 - tinynew.org. 保留所有权利