Ad
  • Default User Avatar

    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. :)

  • Default User Avatar

    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.

  • Custom User Avatar

    HINT: You should probably try to make your function work the same, regardless of the spacing

  • Default User Avatar

    of course "poor readability", bu this is still pythonic :D

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    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!

  • Custom User Avatar

    thanks a lot

  • Custom User Avatar

    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?

  • Default User Avatar

    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

    import codewars_test as test
    import codewars_test as Test
    

    (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 thing

    and 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 well

  • Custom User Avatar

    I 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?

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    Hi,

    • replace: ctrl+H
    • saving: if you run the code against the example tests or the full test (respectively test/attempt), your code is saved (to the condition the code doesn't result in raising an exception).
    • ctrl+S: run example tests
    • ctrl+enter: attempt
  • Custom User Avatar

    Shouldn'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...