Re: value is in list?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Heimes

    Re: value is in list?

    David Hláčik 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.
    Steven's example works but it won't scale for large lists. Sets are much
    faster if you don't require an ordered result.
    >>list_curren t = [ "welcome", "search", "done", "result"]
    >>list_ldap = [ "welcome", "hello"]
    >>diff = set(list_ldap). difference(set( list_current))
    >>diff
    set(['hello'])
    >>list_toadd = list(diff)
    >>list_toadd
    ['hello']

    Christian

Working...