【发布时间】:2018-10-30 21:19:16
【问题描述】:
我有以下方法,它接受一个字典列表并返回一个新列表,其中仅包含具有唯一 phrases 的字典
@staticmethod
def remove_duplicate_phrases(words: List[Dict[str, Any]]):
unique_phrases, unique_words = set(), []
for word in words:
if word['phrase'] not in unique_phrases:
unique_phrases.add(word['phrase'])
unique_words.append(word)
return unique_words
有什么方法可以加快速度吗?
【问题讨论】:
-
您能否展示一下您是如何运行它并解释为什么您认为它很慢?
标签: python python-3.x algorithm