I am printing the letters in reverse, and they have all been appended to an empty list, so why isn't it accepting my code?

def reverse(text):
    reversed_text = []
    count = 1
    for i in text:
        i = text[len(text) - count]
        count += 1



You are somewhat overthinking this... Try following this template:

    VARIABLE_1 = 0
    VARIABLE_2 = ""
        VARIABLE_1 += 1
    return VARIABLE_2

If you get it to work, don't just move on. Make sure you understand why and how it works. If you have any questions about why and how it works please just ask.


i disagree with @aquaphoenix17 given you are so close to a working solution.

you have the reversed_text, but its a list. You can use .join() to convert list to string, then return the reversed string


That works too...

I was just trying to show a more efficient way of solving the problem. Then again, perhaps efficiency isn't your top priority until you actually start asking about it...


it isn't much more efficient then thedogis2 solution, in fact, when looking at preformance, i would go with thedogis2 solution given strings are immutable in python, and lists are mutable



Welp, ... to each their own I guess.


2 posts were split to a new topic: Reverse


2 posts were split to a new topic: Reverse


Strings are immutable, but replacement is still a valid approach.

s += char

This does not append s, but replaces s with s + char, a new string.