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




  

相关话题

  如何理解“from xxx import *这种写法会给你带来无穷无尽的噩梦?”? 
  如何看待培训机构称廖雪峰为“Python之父”? 
  不同编程语言的程序员之间有鄙视链么? 
  Python中使用class()有什么优势 (PS:想知道实际应用中的优势)? 
  你们都是怎么学 Python 的? 
  为什么国内每天都在说 Python 有多好,真正招聘的时候却不需要呢? 
  如何看待知乎、饿了么后端的招聘纷纷由 Python 渐渐转向 Java? 
  GitHub 上有哪些,简单、易学的 Python 项目? 
  python中怎么利用len(x)补零? 
  作为非计算机专业的学生,觉得 C 语言远比其他语言易于上手,正常吗? 

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





© 2024-05-20 - tinynew.org. All Rights Reserved.
© 2024-05-20 - tinynew.org. 保留所有权利