Message358672
> 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? |
|
Date |
User |
Action |
Args |
2019-12-19 11:12:06 | vstinner | set | recipients:
+ vstinner, rhettinger, mark.dickinson, taleinat, steven.daprano, Yoni Lavi |
2019-12-19 11:12:06 | vstinner | set | messageid: <1576753926.23.0.0437809592277.issue39094@roundup.psfhosted.org> |
2019-12-19 11:12:06 | vstinner | link | issue39094 messages |
2019-12-19 11:12:06 | vstinner | create | |
|