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
  • Custom User Avatar

    Came up with the same solution!

  • 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

    The kata description says that your solution should use with. Start from there. Is with a keyword? Look it up! How does it work?

  • Default User Avatar

    It means that there was an error in the test suite. Your solution failed, but the failure message is missing, which has been fixed. Try again!

  • 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.

  • Custom User Avatar
  • 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!

  • Custom User Avatar

    hi,

    I'm not entirely sure about what you did, but if your problem is only about the id numbers, don't try to keep track of them, just redefine them when you unlock. See:

    The id numbers of the remaining atoms are to be modified so that they are continuous (beginning at 1), keeping the order they had before unlocking the molecule.

    if that's not enough, maybe you have troubles about chaining or you're not removing some hydrogens when unlocking?

  • 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

    I ran into the same issue! I belive that the intersection operator does not work because the intersection does not include elements that appear in only one of the key lists.

    My solution was to create two new variables - k1 and k2, which were sets of the key lists of c1 and c2 - and use the union of the the two sets.

    Therefore, my replacement was k1.union(k2), which creates a new set with elements from both key sets. Note: union is a built-in function that only works for sets.

    I hope this is helpful!

  • Loading more items...