Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I think the biggest problem is (almost) everyone can vote.
I consider myself prety much a beginner and have eroniously voted for less efficient code because I thought it was the best. Maybe only users with high kuy score should be able to vote for best practices. Or even better, active people vetted by mods.
couldn't agree more, i'm sick of people voting best practice just random stuff, the voting mechanism should be changed
Back in the old days when many people were completing this kata, the starting code was:
If you edit/fork the kata and look at the "Complete Solution", you'll see the legacy of this format is still in place (it's just in a non-public location).
Most kata writers don't bother changing given variable names, since that's not part of the "problem" we're being asked to solve.
So, yeah, people are right that it shouldn't be
bool
, which is why someone updated the kata to change the starting code toboolean
(which, IMO, is just as bad of a name, since it's still the name for a variable type, even if Python proper never uses it; it's like Hungarian Notation, except it's not just a notation, it's the whole name). But, you should keep kata updates in mind when talking about people's ancient solutions: the ground has shifted.To be honest when I wrote this I'd forgotten about the built-in function as I so rarely use it, but I would probably choose a different argument name with that in mind as I agree it's best to avoid shadowing built-ins.
If I wrote it now I'd probably go for
isTrue
as parameter name but not sure it's as clear...It's not a keyword but a built-in function. And yes, it's a bad idea to use it as a variable name.
bool is not a keyword in Python
If bool is, then you can't use bool in variable names.
no need to convert to int after using math.floor() :)
This comment is hidden because it contains spoiler information about the solution
my code is similar to this
Yep, that's why this one shouldn't be ranked highest for Best Practice, the one using the arguement "Boolean" should.
it's called an
antipattern
when you're comparing things to True the wrong way(replying to the replier - codewars doesn't allow you to reply past first level)
Bit harsh don't you think? It's just a conditional operator (python's version of ternary) which was introduced in PEP308 (adopted in 2005) and is common and hardly esoteric.
I notice in your solution you chose an explicit
if boolean == True:
check so perhaps you're objecting to the truthiness check (if boolean:
)? Personally it's not my favourite syntax ("explicit is better than implicit...") but it is considered pythonic - c.f. https://docs.python.org/3.8/library/stdtypes.html#truth-value-testingThis comment is hidden because it contains spoiler information about the solution
Just one thing to note: bool is a keyword in Python, so it's generally not a great idea to use it as a variable name.
Sometimes creating a list for the purpose of calling sum is marginally faster (especially if the list gets longer)
Hence I upvoted this answer along with a very similar one that uses map
Loading more items...