STINNER Victor <vstin...@python.org> added the comment:
> I've tried think of other solutions, such as a generic wrapper for such > functions or a helper to check whether an iterable is empty, and they all > turn out to be very clunky to use and un-Pythonic. So the main use case would be to detect an empty iterable in an efficient fashion? Something like the following code? sentinel = objet() avg = mean(data, default=sentinel) if avg is sentinel: ... # special code path Why not adding a statistics.StatisticsError subclass for empty set (ex: StatisticsEmptyError)? Something like: try: avg = mean(data) except statistics.StatisticsEmptyError: ... # special code path, ex: avg = default Or is there another use case for the proposed default parameter? ---------- nosy: +vstinner _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39094> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com