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

@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)
2 Likes

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.

2 Likes

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.”
2 Likes

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:

1 Like

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]