百科问答小站 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 来做什么? 
  新手如何入门pytorch? 
  Python在数据科学领域能否完全取代R? 
  很多人都说 C# 语法怎么优雅,仅仅是因为 C# 的关键字多吗? 
  Python 中有什么不容易让人察觉的有趣的事实? 
  为什么 Python 工程师很少像 Java 工程师那样讨论垃圾回收? 
  Python 语言有什么奇技淫巧吗? 
  python如何理解map,reduce,filter? 

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





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