What is a more efficient way in Python to return list elements which are not in a second list?

Posted by Hobhouse on Stack Overflow See other posts from Stack Overflow or by Hobhouse
Published on 2010-06-09T05:57:56Z Indexed on 2010/06/09 6:02 UTC
Read the original article Hit count: 189

Filed under:

Is there a faster way to do this in python?

[f for f in list_1 if not f in list_2]

list_1 and list_2 both consist of about 120.000 strings. It takes about 4 minutes to generate the new list.

© Stack Overflow or respective owner

Related posts about python