value is in list?

Steven Clark steven.p.clark at gmail.com
Thu Jun 12 18:46:54 EDT 2008


> Hello ,
> following scenario
>
> list_current = [ "welcome", "search", "done", "result"]
> list_ldap = [ "welcome", "hello"]
>
> result:
>
> list_toadd = [ "hello"]
>
> by words said , i want to check if list item from list_ldap exists in
> list_current if not i want to add it to list_toadd.
>
> Thanks!
>
> D.

list_toadd = [i for i in list_ldap if i not in list_current]
seems to work.

I'm sure there's a way to do it with set objects as well.
-Steven



More information about the Python-list mailing list