List has no attribute: strip? (try a for loop)

I’m considering switching over to another learning site, it just doesn’t worth my money and time to get exercises where I have to use things I just haven’t learned yet.
how do you expect people to resolve this if at this point they haven’t seen anything about loops, list or the use of .append?
it’s just ridiculous!


hello my friend. actually we have been through lists AND loops. just look at the python 3 syllabus. number 4 is lists and number 5 is loops. i don’t have a strong memory but im pretty sure that append should be in the Lists section.

Happy coding!!


i really know how you feel …
but i think it’s a good way to learn coding by this way … you just need to think every time before solving your problem … so here, codecademy told u that .strip() is working with strings not lists , so you need to iterate every element in the list (not the whole list) with for loop or any other loops , because every element is a string and .strip() is working with strings .


14 posts were split to a new topic: Value for love_maybe_lines_stripped did not match the expected value

2 posts were split to a new topic: But not strip a list?

5 posts were split to a new topic: Love maybe lines: ‘list’ object has no attribute ‘strip’

5 posts were split to a new topic: Love maybe lines: does not raise an error; it just doesn’t work…

5 posts were split to a new topic: Some of the exercises are not written well

I see everyone’s issue with this exercise. But i think this is a good way to learn. They expect you to resolve the issue in your own way as long as you hit the over all goal that they ask for. And they have given you all the skills before hand to resolve the issue.

Usually my code is a complete mess after trying to get the answer. Then i look at how i could have made my code more simple, less line, better techniques, and it highlights what more i need to learn. if we got spoon fed everything. We would not learn one of the main aspects i feel this course is trying to teach us, which is how to fix a problem being presented to us under certain parameters using what we know already . After all in the real world we will not be given hints.

I would also recommend getting python 3 on your computer so you can try out your code on there i feeling that helps with my learning process anyway as it allows me to keep perfecting my code in my own time after getting the right answer. And if you don’t have python 3 on your computer at this point anyway then you have not followed the course properly and moved on to quickly.

After all we are not just learning to code we are learning a way of thinking. which unfortunately can be a painful process at times :sweat_smile:


On the other hand, I found the exercise helpful to problem solve. I also got the list error I was trying to strip the list directly. I think the exercises were designed to also help us learn how to debug errors and think of ways to complete the objective.

I appreciated this exercise, too, because we need to apply the concepts from previous topics to arrive at the solution. So to me, it was just a matter of asking: “what have I learned so far that I can use to solve this problem?” And that’s how I ended up with the loops.


If we can’t use String Methods on Lists, then how are we allowed to perform this code:

love_maybe_full = “\n”.join(love_maybe_lines_stripped)

Isn’t .join() a String Method, and isn’t love_maybe_lines_stripped a List? I’m confused.

Thank you in advance for any responses.

You are correct about the type of love_maybe_lines and that .join is a string method but that is an example of a string method where a list is passed as the argument (whether or not that is OK depends on the method). In a loose definition a method is function which belongs to an object. You can only use methods which belong to a given object, for example-

"".strip()   # string method
"".join(x)  # string method where we pass x as the argument
[].sort()  # list method
[].append(x)  # list method where we pass x as the argument

If you swapped these round, e.g. [].strip() then you would get errors as .strip is not a list method which I think was the original point for this thread.

Exactly what arguments you can pass depends on the method itself.

If you’re posting code snippets to the fourm please see How do I format code in my posts? as it’s much easier for everyone else to read :slightly_smiling_face: (especially when indentation comes into play).

1 Like

@tgrtim explained it well. Check out the docs for more information. The argument passed to the str.join() method can be any iterable that’s elements are strings. This would include strings!

blah = "Hello World!" print(blah) blahblah = "@".join(blah) print(blahblah)

Just an advice: don’t get frustrated. I guess with this example you learned that you have to use all the tools you’ve learned so far. It might be frustrating, but remember this is a process you will adapt eventually.


You know, I felt the same in the .split() exercises - I got stuck, and after a while I just decided to look up the solution. But this one, really, was the same kind of instruction as the previous one with the .split(), and I actually felt kinda proud of myself for seeing this. Also, a hint (at least right now, in 2022) gives you this info. Really, I think Codecademy makes it too easy sometimes, but if you just look up the solution, look at the code, think about how it works, and re-write it, then, obviously not entirely on your own, but you will complete the exercise and learn something.

1 Like

Not being able to strip a list clears up the question I had about this exercise. We can only strip the strings, got it :slight_smile:

1 Like

I was quite frustrated for a while, but remained calm and took down the following notes. I hope this helps. It honestly is a trial and error, sometimes I asked myself: “how would I know to use this specific method or loop”. In the directions, there is a distinct word/phrase that should trigger this after a while: “On each line…”. This should tell you that you need to iterate or target each item in the list.

The other thing that helped me was looking at what people have to say in the discussion pages or just plain and simple discovery or research on the internet. I saw that someone said: " We cannot strip a list."

This basically told me: " I should be aware of how I am using the .strip() method with the information given. I need to try different versions and print stuff out and see what happens."

Here are my notes:

  • String Methods - Audre lorde poem, Love, Maybe.

    • How I got past the error: “list object has no attribute, strip”
    1. Asked myself: “since the strip method doesn’t work on lists and only strings”
    2. How can I extract or single out the string inside of the list?
    3. Use a for loop - to select each element or character
    4. For loops Allow you to single out each string inside of the list
    5. Do this by: arbitrarily making a variable (item) in your for loop:
      • for item in list_targeted
    6. When you are striping something you need to strip each string and not the whole list.
    7. I have tried printing out the variable or lists to see what the output was which gave me an idea of where I was in the process.
  • Ex: for line in love_maybe_lines:

    • love_maybe_lines_stripped.append(line.strip(’ '))
  1. This solution gave me an error: “not expected value”
  2. This told me: “I’m on the right path because it’s generating an error that is looking for the value and not just an error about something else.”

I think that the exercises now are just starting to integrating everything we have learned before.
The append and loops have been taught in previous modules during this course.
I believe, and sort of agree, that they want us to just combine all the previous classes, so we can start built some more substancial code.

wish you a happy coding journey! :slight_smile:

Instead of using the equals you need to use .append()

love_maybe_lines_stripped = love_maybe_lines.strip

List Comprehension was also taught in the previous lessons, you may try using it as it’s easier than for loops.

* love_maybe_lines_stripped = [x.strip() for x in love_maybe_lines]