Screen Shot 2017-01-11 at 2.06.31 pm

Why does 'coolstory' not work but 'lemons' does?


While it involves a built-in, list(), I don't think anybody would see it as cheating to use that method to convert a string to a list.

m = list(text)

Cache the repetitive elements in easy to read variables to unclutter your code. It will be easier to analyze.


I don't understand a word of your answer sorry I'm new to coding. Where should I implement that code? Also why did my code work for lemons but not coolstory?


Write in some print statements and run the sample word so you can see what is happening and when. That will give you a better idea what the problem may be.


Note that .remove() does not remove the character in the given position. It removes the FIRST character in the list with the same value. In your case, when your code hits the first-from-the-end 'o' (coolstOry) .remove() deletes the first 'o' (cOolstory) leaving your charlist with 'colsto'. In the next iteration it deletes the now first 'o' leavig charlist with 'clsto'. And .append() keeps hitting the last 'o' and appending it three times in a row.