Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Since you tagged python, isinstance(var, bool) ?
PS. I hate and try not to use python, but if I recall correctly there's some oddities with bools and ints so not sure if it'd work -
I don't know about python but !!x is always a classic one
Edit: `not not x` seems to do the trick -
@123abc Hm okay, no logical operators
How about just `1-bool`. It doesn't evaluate to a boolean but I don't think your original expression does either -
Hazarth95024yBranchless always fascinated me. I don't do it in python because I like to use python as more of a clean to read but less efficient tool. But in C++ I love these
-
kamen69954yWhile this might be a good brain exercise, aren't a lot of compilers doing the optimisation step for you anyway?
-
eo287540014y@kamen i guess it's more about code aesthetics, ya know, having less lines of code... wait no, that's horrible code aesthetics. A lame excuse to have a seemingly better Maintainability Index for saving 2 lines of code
Related Rants
"not boolean" statement can be written as "(boolean+(-1))**2". Pls comment a better alternative lmao
question
python
branchless