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.
HATE RETURN
Hi @Rockkley.
Lambdas are anonymous callable objects. If you want call it later, you must use a variable, no other choice to do that. And here (in codewars) if there no name, unit test cannot check the solution.
For your information, in python, a
def
(and so, a fonction) defined like that create a variable:The variable created is
foobar
, the proof, you can do that:It's the aim of the mechanism under the concept of decorators.
If you prefer i can use these solutions instead of lambda, the solution will be acepted:
I know that lambda is anonymous function, and there's no need to create variable for lambda, but here we need to meet the interface requirements. Requirement here is that
check
is callable.In real world I would not create function for this one liner, that's why I'm showing solution with
lambda
.variable "check" holds the function. and ambda describes the oneliner function.
mult = lambda a,b:a*b
is the same as
def mult(a,b):
return a*b
What do you mean? Do you know how lambdas work? Do you know you can copy the code and make trials on your own to understand how it works? On your own computer, or just here, by clicking on
Fork
just below any solution.Why creating a variable for lambda?
The description did say for style points to create a hello world you would show to your friends. Well, to that I would just like to say that any code I write that I would want to show to friends or colleagues would do the absolute minimum required to get the job done. To me, this is it.
drodger, Thx.
PavlovNikita,
This is only a 'clever' way to solve it and not either the only way to solve it or the most readable way to solve it. I personally prefer longer code when it is more easily readable. However, sometimes, it is efficient to do it in a single-line/shorter-code.
After joining codewars, I have tried to be terse with code to learn terseness. So, now, I try to balance both as ultimately code needs to be read and re-read and maintained.
Thx
Hi, where can I read about this method? nice one.
I believe this fails for index == len(items), the conditional is true so it'll try to look it up but the index is out of bounds.
This creates a list of size len(friday) + len(saturday), while
return total - sum(friday) - sum(saturday)
does not.This is also about twice as slow, because we do two passes through each list (one for creating the longer one and one for summing).
Hahahaha nice one.
Updated.
It's already there
Damn, there are definitely easier ways to solve this kata. But it was fun.
Loading more items...