百科问答小站 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代码为什么输出9个9? 
  Python如何修改内置类型? 
  如何实现 C/C++ 与 Python 的通信? 
  学计算机的男生发这个给我看是什么意思? 
  一行代码可以做什么? 
  Python/Pandas如何处理百亿行,数十列的数据? 
  如何评价中科院计算所发布的「木兰」编程语言体系? 
  Python 常用的标准库以及第三方库有哪些? 
  你们都用 python 做什么呢(除了专职程序员)? 
  python中用isdigit函数判断是否为数字,但当输入为负数是不行?怎么解决? 

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





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