Re: value is in list?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Clark

    Re: value is in list?

    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
  • Paddy

    #2
    Re: value is in list?

    On Jun 12, 11:46 pm, "Steven Clark" <steven.p.cl... @gmail.comwrote :
    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_curren t = [ "welcome", "search", "done", "result"]
    >>list_ldap = [ "welcome", "hello"]
    >>to_add = set(list_ldap) - set(list_curren t)
    >>to_add
    set(['hello'])

    - Paddy.

    Comment

    Working...