gpt4 book ai didi

Python 列表 : Is this the best way to remove duplicates while preserving order?

转载 作者:行者123 更新时间:2023-11-28 20:52:15 26 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
How do you remove duplicates from a list in Python whilst preserving order?
Algorithm - How to delete duplicate elements in a list efficiently?

我已经阅读了很多在保留顺序的同时从 Python 列表中删除重复项的方法。所有的方法似乎都需要创建一个函数/子例程,我认为这在计算上不是很有效。我想出了以下方法,我想知道这是否是计算效率最高的方法?(由于需要快速响应,我对此的使用必须尽可能高效。)谢谢

b=[x for i,x in enumerate(a) if i==a.index(x)]

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com