【发布时间】:2021-09-27 08:21:28
【问题描述】:
我的变量列表words 中有超过 800 个单词。我将前 100 个单词按单词长度拆分并排序为list_one,其余为list_two。
list_one 我得到的是..
list_one = ['1', 'a', 'a', 'a', 'a', 'a', 'a', 'it', 'is', 'in', 'of', 'be', 'in', 'of', 'or', 'of', 'be', 'on', 'is', 'so', 'in', 'of', 'he', 'is', 'of', 'or', 'of', 'my', 'mr', 'and', 'set', 'url', 'org', 'txt', 'man', 'the', 'man', 'may', 'his', 'the', 'the', 'the', 'one', 'his', 'jane', '1342', 'that', 'good', 'must', 'want', 'wife', 'such', 'this', 'well', 'that', 'some', 'dear', 'said', 'lady', 'title', 'pride', 'utf-8', 'https', 'files', 'truth', 'known', 'views', 'first', 'truth', 'fixed', 'minds', 'other', 'their', 'author', 'austen', '1342-0', 'single', 'little', 'bennet', 'english', 'chapter', 'fortune', 'however', 'language', 'encoding', 'feelings', 'entering', 'families', 'rightful', 'property', 'prejudice', 'character', 'gutenberg', 'daughters', 'possession', 'considered', 'universally', 'surrounding', 'acknowledged', 'neighbourhood']
现在我必须将list_one 的列表更改为set。我所做的是:
print(set(list_one))
但是,它显示了list_one 和list_two 混合的随机单词输出。我该如何解决这个问题?我不明白为什么我没有得到list_one 的独特词。
应该是这样的:
['a', '1', 'is', 'he', 'be', 'in', 'of', 'or', 'mr', 'my', 'so', 'on', 'it', 'txt', 'set', 'one', 'url', 'and', 'his', 'org', 'man', 'the', 'may', 'jane', 'wife', 'this', '1342', 'want', 'said', 'some', 'that', 'such', 'must', 'lady', 'well', 'good', 'dear', 'pride', 'https', 'known', 'other', 'their', 'title', 'first', 'truth', 'fixed', 'files', 'utf-8', 'minds', 'views', 'little', 'author', 'single', 'bennet', '1342-0', 'austen', 'chapter', 'english', 'however', 'fortune', 'feelings', 'property', 'encoding', 'rightful', 'entering', 'families', 'language', 'prejudice', 'gutenberg', 'daughters', 'character', 'considered', 'possession', 'universally', 'surrounding', 'acknowledged', 'neighbourhood']
【问题讨论】:
-
请粘贴您的完整代码。