在我目前的任务上。该程序将为每个客户生成一个独特的列表,其中包含5-10个重复的项目,列表长度为40。
我需要在数以百万计的客户中运行这个程序。所以我想知道哪个更快?
# plan A
customer_list = list(set(customer_list))
for item in customer_list:
do something#plan B
for item in customer_list:
do something发布于 2014-06-10 07:10:59
我会为完成的顾客准备一套。它应该比列表更快。
completed_customer = set()
for item in customer_list:
if item not in completed_customer:
-do something //add here the item to the set:发布于 2014-06-10 06:39:28
为了获得更快的性能,您还可以考虑以下选项:
completed_customer = []
for item in customer_list:
if item not in completed_customer:
-do somethinghttps://stackoverflow.com/questions/24134335
复制相似问题