How to improve this code?
Tim Chase
python.list at tim.thechases.com
Mon Sep 14 22:21:34 EDT 2009
More information about the Python-list mailing list
Mon Sep 14 22:21:34 EDT 2009
- Previous message (by thread): How to improve this code?
- Next message (by thread): How to improve this code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> def elementsPresent(aList, match):
> match = set(match)
> for item in aList:
> if item in match:
> return True
> return False
This could be rewritten in Python2.5+ as
def elementsPresent(aList, match):
match = set(match)
return any(elem in match for elem in aList)
though as suggested both places, the set intersection may be fastest.
-tkc
- Previous message (by thread): How to improve this code?
- Next message (by thread): How to improve this code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list