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 could write comments on a fork if you want.
I don't bother since it's not something I'll reuse and people here are those who solved it, so most will be able to understand. :)
idk, looks much less obscure to me than any 10+ lines solutions. Of course comments would be welcome, but even w/o comments this one takes much less time to read and fully understand.
HINT: You should probably try to make your function work the same, regardless of the spacing
of course "poor readability", bu this is still pythonic :D
This comment is hidden because it contains spoiler information about the solution
very clever, but very obscure
I used very similar reasoning on both methods in my solution, but I tried to go for a readable code ando also followed PEP8, resulting in 38 lines against 9.
This solution uses some very cool tricks though, some of which I can surelly use to improve mine.
Congrats on the most succinct solution!
thanks a lot
For working with an outside IDE, can I run the sample tests of a kata without having to change their pattern? For example, I'd like to have access to
Test.describe
,test.assert_equals
and whatever else I may find in sample tests. Do those come from any particular public package or are they exclusive to Codewars?If you look here: https://github.com/codewars/codewars.com/wiki/Language-Python (google: codewars python environment)
they link to https://github.com/Codewars/codewars.com/wiki/Codewars-Python-Test-Framework-V2
which in turn is https://github.com/Codewars/python-test-framework
which you can install with
pip install --user git+https://github.com/Codewars/python-test-framework
and then
(obviously it's odd to import it as two names, but both are used in the example test code for this kata and
print(test is Test)
says they're the same thingand as always when installing something - consider who it comes from, how much you trust them, what you trust them with, and so on.
you could also edit the test cases to use
assert
and run it with pytest, or edit it to fit whatever test framework... probably the same amount of work and works just as wellI have a question not entirelly related to this kata, but I couldn't find another place to post it.
It was recommended to me previously to use an outside IDE for coding for longer katas, and I decided to try that. That said, is there a way for me to run the sample tests without changing them or their pattern? Is there a package I can import that gives me access to
Test.describe
,test.assert_equals
and whatever else I may find in sample tests?I do really recommend working with a proper IDE, especially when you are going to invest "hours of work" in solving of "complex problems".
Honestly, I cannot even imagine working on a challenging kata without proper syntax highlighting, syntax checking, helpful editor features, and step by step debugging. It's really worth it.
Well, I in fact had not run the code yet as I knew it wasn't ready, and I suppose I'm not the only one who does so when solving complex problems. That said, the knowledge that the code is only saved upon testing/attempting can not be expected from an user. Thus, I suggest a periodical, more reliable saving mechanism.
Furthermore, I'll be more carefull from now on and hit Test prematurelly just for the purpose of saving my code. Thank you for the instructions.
Hi,
ctrl+H
ctrl+S
: run example testsctrl+enter
: attemptShouldn't the code I'm writing for a kata be saved, at least, periodically?
I was solving a problem using the website's IDE and decided to exchange a function name for a more meaningfull one. Since it was already being called multiple times throughout the code, I decided to try and automatically replace it. By pressing CTRL+F, I was shown an in-built "Find" tool, with no replacing option though. Then, as a fool, I pressed CTRL+R in hope that a similar tool for Replacing would show. Instead, my browser refreshed and I lost about an hours work... Since the UI has no apparent "Save" button, I expected my code to be persistent to at least some degree.
Loading more items...