百科问答小站 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 需要怎样的基础? 
  为什么 Java 份额那么高,在知乎的存在感却不如 Python? 
  银行业为什么喜欢用 sas 而不是 python? 
  如何看待 Python 3.9 以上的版本不再支持 Windows 7? 
  Python中如果判断一个文件是不是jpg的图片? 
  如何系统地自学 Python? 
  Python 在大部分领域都能胜任,为什么很多企业转向了 Golang? 
  Python 2 和 Python 3 有哪些主要区别? 
  Python 中有什么不容易让人察觉的有趣的事实? 

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





© 2025-02-07 - tinynew.org. All Rights Reserved.
© 2025-02-07 - tinynew.org. 保留所有权利