How to find if an element of a list is in another list?

前端 未结 5 498
误落风尘
误落风尘 2020-12-29 04:43

I want to know if at least one element in a first list can be found in a second list.

I can see two ways to do it. Let\'s say our lists are:

List<         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 04:54

    The second one has better performance on large lists than the first one. Intersect puts the elements of one list into a hash table before checking the other list's elements for membership.

提交回复
热议问题