Ad
  • Custom User Avatar

    The complexity is 2^n. if string length is very large, this method maybe very slow

  • Default User Avatar

    I think there may be some weird string issues with Codewars' implementation of Python, and I'm still trying to figure out what those issues are. I will give out that in the solution, all strings provided to the class use the decode method with 'utf-8' as an argument, and then, with the final output, run 'encode' on then transformed string with 'utf-8' as an argument.

  • Custom User Avatar

    I try to convert all strings to unicode by using str.decode("utf-8") but it fails.

    I was wondering how you convert katakana?

  • Default User Avatar

    I decided to spend some more time researching this today rather than remaining oblivious. The test cases expect default-type strings for I/O. The kata editor input, meanwhile, is in utf8. I.e. you need to convert all strings from ASCII to unicode and back. You can totally blame me for approving the kata translation. Meanwhile, I decided to investigate reconciling this, but ran into some issues (not limited to test cases being locked), so I've contacted Codewars about that.

  • Custom User Avatar

    But after I comment this line,
    There is no UnicodeEncodeError.

    Problem happens on katakana
    And I use chardet.detect to detect the code infomartion, the result is 'utf-8'
    So I think decode("utf-8") is correct?

  • Default User Avatar

    key = key.decode("utf-8")

    UnicodeEncodeError: 'ascii' codec can't encode

    The problem is somewhere else.

  • Custom User Avatar

    I try to transfer code to "unicode" by:
    key = key.decode("utf-8")
    the result is
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

    But it work well on my computer. with python 2.7.
    Does anyone know why?