有没有更快的方法在Python中计算这个值:
len([x for x in my_list if x in other_list])
我尝试使用集合,因为列表的元素是唯一的,但是我注意到没有任何区别。
len(set(my_list).intersection(set(other_list)))
我正在处理大量列表数据,即使是最微小的改进也能提升效率。谢谢。
len(set(my_list).intersection(set(other_list)))
。 - van