value is in list?

Paddy paddy3118 at googlemail.com
Fri Jun 13 07:11:16 CEST 2008


On Jun 12, 11:46 pm, "Steven Clark" <steven.p.cl... at gmail.com> wrote:
> > 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

>>> list_current = [ "welcome", "search", "done", "result"]
>>> list_ldap = [ "welcome", "hello"]
>>> to_add = set(list_ldap) - set(list_current)
>>> to_add
set(['hello'])

- Paddy.



More information about the Python-list mailing list