"in" operator for strings
Ruediger Soerensen
soerense at verwaltung.uni-mainz.de
Thu Feb 1 10:01:47 EST 2001
>This is exactly one of my current puzzles: How to can I compare that a set is
>a subset of another, larger, set efficiently? Say I have to perform such a
>comparison some 100000 times, it would come in very handy to write
>
>(assume all_sets is a list of 100000 sets (i.e. lists))
>
>for set in all_sets:
> if [1,2,50] in set:
> do_something
>
>any good suggestion?
What about this:
def inset(subset,set):
for u in subset:
if not u in set:
return 0
return 1
print inset([1,3],[1,2,3,4])
print inset([1,8],[1,2,3,4])
--
Rüdiger "Black Hole" Sörensen || soerense at verwaltung.uni-mainz.de
More information about the Python-list
mailing list