百科问答小站 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中一个字符串的所有字母用它的后继字母代替(比如,a用b代替,b用c代替),怎么搞? 
  python setup.py data_files 设置要拷贝的文件,不能拷贝到安装目录下。要怎样解决? 
  电脑存在“熟悉”某项任务后运行变快的情况吗? 
  这个python代码为什么输出9个9? 
  为什么python整数除法运算得浮点数? 
  计算机视觉研一,只学过Python基础,目前代码能力很差,要不要换导师,不换的话如何毕业? 
  Python 的 dict 不会随着 key 的增加而变慢吗? 
  如何看待风变编程的 Python 网课? 
  为什么自学Python看不进去? 

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





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