Message387248
I can't recall where I saw this originally, but you can use the spaceship operator "--0--" to turn floor division into ceiling division:
>>> 12//5
2
>>> --0-- 12//5
3
There's also the ++0++ operator when you want to emphasize that you really *do* mean floor division:
>>> ++0++ 12//5
2
But yes, -(-n // d) is the easy (if a little bit cryptic) way to get the ceiling of n / d. |
|
Date |
User |
Action |
Args |
2021-02-18 17:21:42 | mark.dickinson | set | recipients:
+ mark.dickinson, gvanrossum, rhettinger, vstinner, serhiy.storchaka, PedanticHacker |
2021-02-18 17:21:42 | mark.dickinson | set | messageid: <1613668902.47.0.497350109057.issue43255@roundup.psfhosted.org> |
2021-02-18 17:21:42 | mark.dickinson | link | issue43255 messages |
2021-02-18 17:21:42 | mark.dickinson | create | |
|