【发布时间】:2021-10-12 16:22:15
【问题描述】:
我从一段文本中提取了一个单词列表,但我想从该列表中删除重复的单词。我该怎么做?
我的输出:
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'and', 'and', 'breaks', 'east', 'envious ','公平','悲伤','是','是','是','杀','光','月亮','苍白','生病','柔软','太阳', 'sun', 'the', 'the', 'the', 'through', 'what', 'window', 'with', 'yonder']
期望的输出:
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', '羡慕', 'fair', 'grief '、'是'、'杀'、'光'、'月'、'苍白'、'病'、'软'、'太阳'、'之'、'透'、'什么'、'窗'、 '与','那边']
【问题讨论】:
-
set()适合这个目的 -
Jussi 的回答是正确的。最简单的方法
-
请阅读How much research effort is expected of Stack Overflow users? 至少,您应该在询问之前进行快速的网络搜索。还请使用tour,阅读what's on-topic here、How to Ask 和question checklist,并提供minimal reproducible example 来展示您的尝试。欢迎使用 Stack Overflow!
标签: python-3.x string list