Jul-18-2018, 02:32 PM
Hello,
I was given a homework, the output should look like this:
W
Wo
Wor
Worl
World
World
World H
World He
World Hel
World Hell
World Hello
The teacher suggested this solution:
I was given a homework, the output should look like this:
W
Wo
Wor
Worl
World
World
World H
World He
World Hel
World Hell
World Hello
The teacher suggested this solution:
userInput = 'Hello World' userInput = userInput.split(' ') userInput = userInput[::-1] userInput = ' '.join(userInput) tmp = '' for char in userInput: tmp += char print(tmp)I dont understand why we need an additional tmp variable. Could someone please explain it to me, or have a better, more pythonic solution?