Parametrized any() and all() ?
16 Jan
2013
16 Jan
'13
2:30 a.m.
Hello any() and all() are very useful small functions, and I am wondering if it could be interesting to have them work with different operators, by using a callable. e.g. something like: import operator def any(iterable, filter=operator.truth): for element in iterable: if filter(element): return True return False For instance I could then us any() to find out if there's a None in the sequence: if any(iterable, op=lambda x: x is None): raise SomeError("There's a none in that list") Granted, it's easy to do it myself in a small util function - but since any() and all() are in Python... Cheers Tarek -- Tarek Ziadé · http://ziade.org · @tarek_ziade
4086
Age (days ago)
4090
Last active (days ago)
16 comments
13 participants
participants (13)
-
alex23
-
Antoine Pitrou
-
Eric Snow
-
INADA Naoki
-
Laurens Van Houtven
-
Masklinn
-
Nick Coghlan
-
Oleg Broytman
-
Oscar Benjamin
-
Ronald Oussoren
-
Steven D'Aprano
-
Tarek Ziadé
-
Terry Reedy