Ad
  • Default User Avatar

    Only thing to note about this pattern is that every boolean statement is evaluated. It's fine here, but if the conditionals were more complex/long-running functions, every single one of them would be called. You could instead return a function from the dictionary, and call that function with the num argument, to evaluate it.

  • Default User Avatar

    The solutions that use sorting may be shorter in code length, however this code and similar variations are shorter in execution time, O(n).

  • Default User Avatar
  • Default User Avatar

    To specify the exception, in this case it would be a TypeError for trying to iterate over an int or None. Not sure what other types are present in the tests. If it is some other iterable, like a list of ints, the exception would be an AttributeError since the int type does not implement .lower()

  • Default User Avatar

    no need for 'digits' to be a list. You can pass str(n) into the map since it's iterable in the same way

  • Default User Avatar

    It seems the codewars wikipedia may have changed again? - 11/04/20

    The expected results differ between the sample test and full test. Seems the links under 'See Also' are expected in the full suite, but not in the sample test.

  • Default User Avatar

    Could someone please help me with this Exit Code?

    File "main.py", line 57, in <module>
        test.fail()
    TypeError: fail() missing 1 required positional argument: 'message'
    

    I am passing all sample tests but not the full test. I know most likely the problem is with my implementation :) but wanted to check.

  • Default User Avatar

    Thanks for the reply!

    My implementation is 'tracking' atom creation via a simple attribute in the Molecule instance, in order to provide the next continuous id number to new atom instances created from the brancher, add/add_chaining, and closer methods.

    When unlocking, I am noting which atoms will need to change id number, then updating them after all hydrogens have been removed.

    My main assumption: If atoms remaining in the molecule have a higher id number than a deleted hydrogen, they were created after, so their id number should decrease (There is 'room' below them)

    Working on a better way to do this, as I think it may be simpler

    Edit: Figured it out. Was way simpler, haha. Thanks!

  • Default User Avatar

    I am primarily getting tripped up by the reordering of the ids during the unlock method.

    I'm passing the fixed tests for the full test suite (thanks so much for the GREAT test suite btw), but failing a handful of random tests. Examining the 'actual' versus 'expected' output, I'm usually off by one or two for my id values. It's pretty likely the way I'm tracking atom.ids is extremely janky from the get-go, and by the time I'm removing hydrogens and possibly dealing with orphaned chains/branchs, it's all gone to sh**. Without giving too much away, is there some suggested design to be using here? I understand if this question can't be answered without spoiling the solution. I've just been working for a few days on this one and was feeling so close but now totally stuck. Any nudges in the right direction greatly appreciated, thanks!

  • Default User Avatar

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