How to improve this code?
Tim Golden
mail at timgolden.me.uk
Tue Sep 15 12:15:58 EDT 2009
Sol Toure wrote:
> def are_elements_present(sourceList, searchList): for e in searchList:
> if e not in sourceList:
> return False
> return True
>
>
> Using set:
> def are_elements_present(sourceList, searchList):
> return len(set(sourceList).intersection(set(searchList)) ==
> len(searchList)
Unless I'm missing something, (and I didn't bother to
read the original code so I may be) that's a subset test:
set (searchList) <= set (searchList)
TJG
More information about the Python-list
mailing list