Common elements between two lists with no duplicates

后端 未结 5 1347
时光说笑
时光说笑 2021-01-16 05:19

Problem is this, take two lists, say for example these two:

a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
         


        
5条回答
  •  心在旅途
    2021-01-16 06:02

    Using intuition of sets, You could do something like this...

    filtered_arr = list(set(b)-set(a))

    First you convert 2 arrays into sets, then take the substitute of it convert the result into the list again.

提交回复
热议问题