百科问答小站 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]     




  

相关话题

  为什么很多人喜欢 Python? 
  你都用 Python 来做什么? 
  初学者想自学python有什么资料可以进行查阅? 
  VBA会被Python代替吗? 
  为什么 Python 工程师很少像 Java 工程师那样讨论垃圾回收? 
  Python和 C 语言有什么不同? 
  Python中有什么方法能将一段英文里的不重复单词挑出来? 
  新程序员如何向英文社区(如github)进阶? 
  知乎的架构在大型社交网站中属于什么水平? 
  python中用isdigit函数判断是否为数字,但当输入为负数是不行?怎么解决? 

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





© 2025-03-11 - tinynew.org. All Rights Reserved.
© 2025-03-11 - tinynew.org. 保留所有权利