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.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
i complicated it for no reason :D
Please use spoiler flag also in solution comments as your comment is visible on the main page.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I became your fan for that
+1 @PomPolock, I wrote the lambda until I realized I had to list() the filter object. Then re-wrote as a list comprehension. Surprised that the testing structure doesn't let you check for the method used (see https://www.codewars.com/kata/59441520102eaa25260000bf).
Yeah just for the purpose of the kata since that is the direct equivalent JS's Array Filter function. It's good to understand the lambda syntax for usage with map and reduce, as well as other more involved filter functions (where it wouldn't be as appropriate to use the "x for x" expression). Objectively though, neither solution is better than the other if the only goal is to return an array with only even integers.
It's kind of similar in a way to the dynamic programming problems with the fibonacci or factorial sequence where you utilize recursion. For the purpose of writing a function that generates those sequences, recursion isn't necessary but it makes for good practice to start developing an understanding of it.
For many complex programming topics, it's usually easier to understand how they work in a simple problem that may not necessarily require their usage. But learning how they work on the simple problems will make the more complex problems that require them more easy to understand.
Ah, so you're trying to say thah it would have been better to use filter with a lambda function other than a conditional like this ?
While this solution effectively works the same and is definitely a correct answer to the problem, I would say that it somewhat defeats the purpose of the kata. Due to the nature of python, it is not reasonably possible to limit syntax usage in manner that you're able to in JS, especially for this problem. Perhaps I might have been able to have the function return the filter expression instead of the filtered array itself, but that might have been overkill for a white kata.
This is not at all a wrong way of "filtering" any array using a conditional, but doesn't do anything to teach the usage of lambda expressions in python. In most practical environments you would probably use the "element for element in iterable" expressions, but it is useful to understand how lambda expressions work.
There are ~40 completions in Python, they run in about 2000-4000 ms.
Because Raul decided that was the last step, and didn't want you to do something else like filter all non-primes, remove all perfect squares, etc. . Once you figure out what has to be done, it is very simple coding.
This doesn't help the fact that I want to understand the task before trying it. This is not a
puzzle
, so the instructions should be clear enough not to make me look at the actual tests in attempt to figure out what the author wants me to do.Hint: Take a look at the expected output of the sample tests. There is a consistent part of the answer that will help you know when you have the output it expects.
Loading more items...