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.
well i don't know what to says from a practical stand point it is faster but from do you really wanna do it in your code like that and hard code it i don't think so
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.
As a new python developer, this solution helped me immensely. Thank you.
well i don't know what to says from a practical stand point it is faster but from do you really wanna do it in your code like that and hard code it i don't think so
Very clever! Good catch that you didn't need to translate '456', as their position remains the same.
Hi I'm new here and i need someone to guide me in coding
nice
escalated here as an issue
This comment is hidden because it contains spoiler information about the solution
how does it determing that the string is odd or even and which output to give
best answer
This comment is hidden because it contains spoiler information about the solution
nah, amazing , i did it in like 100 lines of code.
Good catch, just grabbing the .length of collection! Reduces the memory usage to constant space complexity.
wow, the well deserved 6006 clever vote!
Loading more items...