Comments indicated that what I did here is not the best solution. Like noted in my original post, a
set would be better in this case. I eventually used
set(r).issubset(set(l)). Marius also pointed out to
set(r) <= set(l), but I like the
issubset one more.
I wanted to check if every element of one list or tuple is part of another one using Python. A
set has the
issubset()-method, but I couldn’t find anything build-in for a tuple. It was, however, rather quickly done:
``` »> r = (1,2) »> l = (3,4,1,5,2) »> False not in [ e in l for e in r ] True »> r = (1,9) »> False not in [ e in l for e in r ] False
``` Why I’m posting this? I just found it cute code, somehow.
If you like to leave a comment, but don't like to use Disqus, please send an email instead. Comments by email might end up as a FAQ here under.