Simplify? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Simplify?

I think I could have done this better. I was supposed to use recursion to seperately print out the letters of an input string backwards. The codee works, but I'm pretty sure I could have done it without converting the string to a list. I also think I could have made the code more compact. I would appreciate anybody's input on this. https://code.sololearn.com/cMofjUnKLTQc/?ref=app

23rd Sep 2021, 10:43 AM
Terry Petersen
3 Answers
23rd Sep 2021, 11:04 AM
Arsalan [Inactive]
Arsalan [Inactive] - avatar
+ 2
Terry Petersen As Arsalan has demonstrated with his excellent code, you can slice and manipulate strings in a similar manner to lists
23rd Sep 2021, 11:15 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Thank you for the answer. For some reason I didn't think I could remove letters from a string because they are considered "immutable", but I guess I misunderstood what that meant (ie. I was conflating the string itself with the variable assigned to it).
23rd Sep 2021, 11:43 AM
Terry Petersen