Ad
  • Custom User Avatar

    So what I was missing (and that other guy's explanation fails to explain) is that when slicing a string to return a substring the : denotes a start and end point. s[] doesn't JUST return a specific indice. You can use it to return a substring from a starting indice to an ending indice. What the other guy is explaining is that the math works out so that on an odd string the equations on both sides of the : return the same number, so a string with 11 characters would be sliced starting at the 5th (starting from 0) indice and ending at the 5th indice. And even string length returns two different indices, so the one liner works.

    I had to look this up, his explanation did not make sense to me at first either, and frankly I will always pefer easily readable functions to one liners like this in actual production.

  • Custom User Avatar

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