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




  

相关话题

  tkinter可以做出多复杂的界面? 
  Python 的 dict 不会随着 key 的增加而变慢吗? 
  27岁想转python,是否值得? 
  Python中有什么方法能将一段英文里的不重复单词挑出来? 
  如何看待 Python 之父关于帮助中国程序员应对 996 工作制的讨论? 
  为什么很多人都说 Python 简单? 
  如何看待“Python星人”这个群体? 
  这样漂亮的科研结果展示横向柱状图怎么画? 
  Python 打包成 exe,太大了该怎么解决? 
  如何评价 Python 基础知识难度大吗? 

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





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