What is the efficient way to find the non duplicate items in two list ?
List_finish = [1,2]
List_Raw =[1,2,3,4,5]
List_unfinished = []
for raw in List_Raw:
if raw not in List_finish:
List_unfinished.append(raw)
I want to get a List_unfinished with [3,4,5] .
The above for loop is very slow in large list. Any efficient method ?
Posted Apr 20, 2020, 3:36 PM UTC
13
Convert your lists to sets first, then you can just do
set_unfinished = set_raw - set_finishSo laconic but fast. Thank you so much