Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • Hi there, I thought I understood the logic, but when I tried to replicate this solution step by step it didn't remove leading and trailing whitespace. Why is that?
    Step by step:
    first=song.replace('WUB',' ')
    first.split()
    separator=''
    return separator.join(first)

    Could anyboudy explain me why it didn't work?

    Thanks in advance!

  • 🦆 cause multiples WUB should be replaced by only 1 space...

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

  • Python 3 should be enabled.

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

  • Thats nice!

  • 这么打击人回回一行搞定

  • The str.strip() method will actually remove all leading and trailing whitespace by default--including spaces, tabs, newline, return, and formfeed.
    link: https://docs.python.org/3/library/stdtypes.html#str.strip

  • The only way I can imagine you could've gotten an error similar to that was if you called str.split() without an instance (as written) getting the error:
    descriptor 'split' of 'str' object needs an argument

    If you are (or were at the time) new to python you may have forgotten what your parameter was named (likely song), thinking instead that it was called str (as string parameters often get named in other languages).
    This would've resulted in you calling a non-staic method of the string class without any instance for it to refer to.

  • It's not clear if the input list of coins is sorted, the description (coins_list = d1 < d2 < · · · < dn) seems to suggest so but in one of the examples the input list isn't sorted.

  • The regular expression one makes a faster program... just saying. C:

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

  • Man, the solution without regular expressions was simpler than I thought.

  • Sure.

    The '(.+?)' matches any sequence of one or more characters and saves it into backreference '\1'. Then the '\1*$ is just checking if the captured substring is repeated throughout the rest of the string.

    The twist is, because the operator '?' appears in the front of '+', the regex engine will perform the match lazily. By lazily it means that it tries to match as few characters as possible before trying to match the rest of the pattern. That way, it's ensured that problem specification is met, that the repeated substring is the minimum repeatable substring. That would not be possible if the '+' alone had been used instead.

  • Loading more items...