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.
Yeah, I honestly have no idea what my train of thought there was haha. It was a decent while ago, I suspect during the period when I was mindlessly going through a number of 8 & 7 kyu kata without giving them much attention. That's likely why the semicolon at the end of that line is missing as well.
Oops, sorry about that missing spoiler. I haven't been as active on Codewars recently and seem to have forgotten that etiquette.
Also, thanks for the shortened version.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
No problem at all, and good luck (: Feel free to ask any questions, I'd be glad to help.
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.
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.
While this kata is still possible to solve using a method like this (due to it being an easy one and not requiring optimization), I would highly recommend learning the syntax of filter. It's great to learn as a programmer, and in general has a higher degree of effiency for these types of problems (no wasted time efficiency from multiple .append() calls and resizing the list).
If you're entirely stumped it's not a bad idea actually to unlock the solution. However, make sure you take the time to analyze the solutions of other users until you understand what you were getting stuck on. Once you feel like you have a solid understanding of what you were missing, attempt to solve the kata again (even without the reward incentive) without having to look back at the solutions. Otherwise, there's not much benefit to unlocking them. If you're concerned about losing out on potential honor, there's over 5k challenges on the website, so it's not really a big deal if you can't get points for a few of the harder ones.
Remember to utilize the language's documentation and other resources if you get stuck before unlocking the solution though. Often times what I'll do is bookmark the challenge I'm stuck on, and spend some time doing research on it. If it still doesn't come to me, I'll bookmark the kata and attempt to solve it later, usually I come back at it later with some new ideas. In most cases, this works out for me. But, I've had to unlock solutions a few times, especially when I first started the 4kyu+ optimization challenges.
Added the suggested changes. Thanks for the tips, I had thought at the time that
/[A-z]/
was a shortcut, good to know otherwise. It makes sense now that I think about it, since there's characters with codes between the capital and lowercase letters, so that range would unintentionally include those. Also added a bunch of symbols to the char string to improve testing.Apologies for the late reply, looks like I didn't get any notifications for feedback on this translation for some reason. I just noticed it after making another translation and saw that this one had some comments.
Is there a decent way to get more attention to these translations? I posted the most recent one I made on the gitter chat and in the suggestions for the kata, but it seems like they tend to sit in a "purgatory" of sorts for a long time if the author is inactive. I think there's quite a number of older kata with inactive authors that could use translations, and I could use the test framework experience. However, it is quite discouraging to do them when they recieve so little attention, and it can be significantly more time consuming than just completing katas.
This solution might have been acceptable on a lower level kata, but once you reach 5kyu and especially in the 4kyu+ range, it's important to have a solid understanding of optimization. I can't spell it out for you (since that won't help you learn), but to point you in the right direction, I'll tell you some problematic areas.
When you convert the entire array into two seperate enumerates, you're creating a lot of unncessary overhead. Try to think of a way to acomplish the same thing without reconstructing the entire dataset. If that's too much to do at once, try to use one instead of two. Doing so correctly will almost double your efficiency, as you'll iterate through the data once instead of twice. Bonus tip: this problem can be solved in many ways without using enumerate, or keeping track of the index at all.
Also, every time you try to get the index of an element or transform the array (appending or removing elements) there is a cost associated with doing so. Try to figure out a way to remove the excess directions without making so many .remove() and .index() calls.
As a side note, the practice of excessively using try-except blocks can also cause unneeded overhead and in general is not a very optimal programming practice. In some cases, try-except is necessary, but in this case and many others it's better to figure out a way to solve the problem without having to resort to exception handling.
I can understand your frustration, because I was in your shoes not too long ago. You come up with a solution that "works" but is incredibly slow in comparison to what it could be. A lot of programming is not about creating a rough draft that barely functions, but creating an optimized solution that performs efficiently. Efficiency is very relevant in the professional world as well, imagine the level of optimization a company like google has to do in order for them to index through millions of search results for countless customers at the same time. They're a high end example, but that happens to a smaller degree even in small-medium sized businesses.
Edit: if you are looking for any other ways to improve or hit a wall, be sure to look up "python time complexity" or "python optimization" and "dynamic programming". There are also countless tools out there to assess your code and determine which parts are taking up the most time. It's a great idea to run the code in an IDE without a time limiter, and slowly work on reducing the run time (rather than just trying to get it to pass the CodeWars tests). Optimization is one of the biggest hurdles that people have along the road to becoming a competent developer. But once you figure it out properly, you'll significantly improve as a programmer.
I think I'll leave it in the description as the "preferred method" as I think it's good for people to learn how to use map, filter, and reduce, but if people just use list comp instead it's not the end of the world. It's just a white kata. CodeWars is one of those sites where you can either take the time to learn new things or just use shortcuts for easy points. When creating kata or translations, there's some level of rule enforcement that can be done but there's not much to actually stop people from using shortcuts entirely.
If it's possible to do so in a manner that wouldn't be ridiculous I wouldn't be entirely opposed to doing so, but the orginal challenge does not include that in any part of the test cases. Personally I think that translations can improve upon the testing procedure by using randomization and having better descriptions/feedback, but shouldn't have any additional checks/rules beyond the original kata.
Added sample tests in my Python translation, if anyone with the honor required to edit katas wants to include them in the format in the JS version, feel free.
Created a Python translation for this kata, with random tests and sample tests. Also created a Python-specific description for the kata. Here's the link: https://www.codewars.com/kumite/5cdc7b84accbd30018458874?sel=5cdc7b84accbd30018458874
Feel free to provide feedback, anything constructive is more than welcome. If it's good enough, I would also highly appreciate an approval (:
Loading more items...