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




  

相关话题

  如何让停留在语法层面的 C++,变成实际工程中的 C++? 
  数据分析为什么常用Jupyter而不是直接使用Python脚本或Excel? 
  数据分析为什么常用Jupyter而不是直接使用Python脚本或Excel? 
  怎么自学python,大概要多久? 
  Python中一个字符串的所有字母用它的后继字母代替(比如,a用b代替,b用c代替),怎么搞? 
  仅就作图而言,Python 和 MATLAB 有可比性吗? 
  vlang,nim等新兴语言未来是否有可能掀翻go,rust,Python等老牌热门语言的霸主地位? 
  Python有哪些杀手级超厉害框架或库或应用? 
  python适合什么年龄自学? 
  为什么C++没有Python那么多开源库? 

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





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