FAQ: Learn Python - Practice Makes Perfect - reverse

faq

#1

This community-built FAQ covers the “reverse” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise reverse:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!


#2

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

#4

turnt =
def reverse(text):
print text
for let in str(text):
print let + " let"
turnt.insert(0, let)
print turnt
return turnt

Returns the following,

abc
a let
[‘a’]
b let
[‘b’, ‘a’]
c let
[‘c’, ‘b’, ‘a’]
Python!
P let
[‘P’, ‘c’, ‘b’, ‘a’]
y let
[‘y’, ‘P’, ‘c’, ‘b’, ‘a’]
t let
[‘t’, ‘y’, ‘P’, ‘c’, ‘b’, ‘a’]
h let
[‘h’, ‘t’, ‘y’, ‘P’, ‘c’, ‘b’, ‘a’]
o let
[‘o’, ‘h’, ‘t’, ‘y’, ‘P’, ‘c’, ‘b’, ‘a’]
n let
[‘n’, ‘o’, ‘h’, ‘t’, ‘y’, ‘P’, ‘c’, ‘b’, ‘a’]
! let
[’!’, ‘n’, ‘o’, ‘h’, ‘t’, ‘y’, ‘P’, ‘c’, ‘b’, ‘a’]

how do I stop this from happening?


#5

if you call the call the function multiple times (please try this), you will see that the list accumulates data from all the function calls, so the list doesn’t “reset”. How could we fix this?


#6

Well what I tried was to call break after the function so that it would stop the process and then start over a new. But what it did was went through and gave me C, B, A and completely stopped and didn’t do anything on the next Python argument. Then I try to .clear() and that didnt work. I’m not sure if that’s a Python three thing and I was looking at the wrong Python version for a solution. But that didn’t work so I guess I could try to maybe do pass but I think it will do the same thing as break. I could do it in a certain way in which I could say if we find the a or B or C delete them but that’s not the spirit of what they’re trying to get me to do. And it doesn’t look like it would work for all arguments plus you have a problem with the first argument and maybe I could do it in a on the first round accept abc and on the second round not accept. But then I’m not actually finding the solution to my problem. I could maybe enumerate the list and say however many are enumerated delete the same before you add a second list. Just seems like there should be a way easier solution.


#7

there should be, and there is.

The list now accumulates data because you define it once when the program/script start running, so as long as the program runs, the list just gets more and more data

so that doesn’t seem to be the right place to define the list


#8

turnt[0:-1] =
no good here


#9

yes
I seeeeee! For some reason I did not catch that but now that I’m thinking about it I’m remembering5 watching videos about objects and how their variables are only accessible within the object. Data were not there yet I just seen some videos on it and it makes sense to me now is wondering why wouldn’t this reset but it’s not inside the functions would not.


#10

Thank you very much I totally didn’t see that I started making the function I realized that I needed a variable and it is part of the top because it was easier for now I see the importance of putting the variable in the function instead of where it is most convenient on the page. My bad


#11

putting variable at the top (or nearly) also has its use cases, but not in this case

do you understand now?


#12

Yeah definitely catch it in the function I need to reuse it and I needed to clear out every single time the once my variable is outside of the function it’s a variable that has the ability to be added to from various functions. But if I needed just for the function and not for some more global use it’s very problematic to put it outside of the function since the list has no global purpose just taking it harder on myself