Ad
  • Custom User Avatar
  • Custom User Avatar

    I was baffled by this signature of the translate method until I realized "Python" here means Python 2.

  • Custom User Avatar

    Most readable of the one-liner solutions I see here.

  • Custom User Avatar

    Fair enough. I love Python, my career revolves around it, but sometimes I just want a little more rigor in the type system! Props to Python 3 for disallowing ordinal comparisons to None.

  • Custom User Avatar

    That's because of Python's duck typing – bool is a subclass of int.

    print(False == 0 and True == 1) # Prints "True"
    

    And since the description asks to return 0 when the numbers are equal and False is equivalent to 0, this is acceptable.

  • Custom User Avatar

    well, that'd be pretty anti-pythonic, tho... ;)

  • Custom User Avatar

    I'm guessing by "false extending 0" you mean to point out that False == 0? Sure, but take note also that False is not 0.

    My point was just that the description (i.e. acceptance criteria) states "when a is close to b, return 0" (type int) while this returns False (type bool). Python's weak typing in this area makes it easy to be casual. But if you added type annotation to this function and enforced it (say, with mypy or enforce), returning False would be an error.

  • Custom User Avatar

    but false extending 0, if the expected answer is 0, that's still correct.

    proof: this passes this fixed test: test.assert_equals(close_compare(5, 5), 0)

  • Custom User Avatar

    This returns False if a and b are equal. (I posted a comment in discourse also, since this suggests the tests need tightening.)

  • Custom User Avatar

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

  • Custom User Avatar

    That's not the problem though; the main problem is that it's not even half-finished (just look at the tests and import statements). Fixing it would require pretty much writing up the whole test.

  • Default User Avatar

    It's on the list: https://github.com/Codewars/codewars.com/wiki/List-of-Affected-Kata The question is whether the packages will be installed or not.

  • Custom User Avatar

    Clojure: it's unfinished and should be revoked/removed.

  • Custom User Avatar

    Tests require result to have a specific ordering but it's not mentioned anywhere. Either it should be specified, or the test should sort the user result before comparison, or the function should return a set instead.

  • Custom User Avatar

    @pbx,

    Instead of just showing it in the description (and then forcing everyone to write their own), it might be a good idea to add the digits dictionary to Preloaded since every solution has the same dictionary. That way people could choose whether to use a preloaded dict of digit/letter pairs or to write their own (I'm guessing many people would use the preloaded dict).

    LETTERS = {
        '2': 'ABC',
        '3': 'DEF',
        '4': 'GHI',
        '5': 'JKL',
        '6': 'MNO',
        '7': 'PQRS',
        '8': 'TUV',
        '9': 'WXYZ'
    }
    

    If you do add that to Preloaded, just make sure to tell people about the name of it in the description too. You could use separate markdown code sections for each language (so the Python dict only shows up in the description for Python not Clojure and vice versa).

    Thanks!

  • Loading more items...