百科问答小站 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 常用的标准库以及第三方库有哪些? 
  python如何将变量名转化为同名字符串? 
  Python有哪些杀手级超厉害框架或库或应用? 
  我想学Python,结果买了Python3.4.3的书,可以在Python3.6.4上用吗? 
  为什么 Python(或 Ruby、Perl 等)没有取代 Bash 成为系统 Shell? 
  为什么很多程序员不用 switch,而是大量的 if...else if ...? 
  有哪些 Python 大牛的 blog 推荐? 
  Python中除了matplotlib外还有哪些数据可视化的库? 

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





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