Rita Sue and Bob too

Andrew Durdin adurdin at gmail.com
Fri Aug 20 20:13:03 EDT 2004


On 19 Aug 2004 19:10:34 -0700, Cyrille Lavigne <dontreply at caramail.com> wrote:
> If you dont want them in order you should do:

If you don't want them in order, then the sets module is probably the
clearest way to go:

from sets import Set

names = ["Rita", "Jim", "Bob", "Jane", "Sue", "Jerry"]
searchnames = ["Rita", "Bob", "Sue"]

nameset = Set(names)
searchnameset = Set(searchnames)
if searchnameset.issubset(nameset):
    print "They're all found"
else:
    print "They're not all found"

-- Or you can eschew the temporary variables, and just say use
Set(searchnames).issubset(Set(names)), but this is a little less
clear.



More information about the Python-list mailing list