My solution doesn't give the expected value, I don't know what the expected value is

love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ','\n' ,'   to conquer me home.    ']

love_maybe_lines_stripped = []
for line in love_maybe_lines:
  line = line.strip(' ')
  love_maybe_lines_stripped.append(line)

print(love_maybe_lines_stripped)

Please post a link to this exercise so we can do some checking. Thanks.

Thanks for responding!
here’s the link to the exercise: https://www.codecademy.com/courses/learn-python-3/lessons/string-methods/exercises/strip

This is what your output should look like…

Always
in the middle of our bloodiest battles
you lay down your arms
like flowering mines

to conquer me home.

I’m still stuck on the 1st task:

First, use .strip() on each line in the list to remove the unnecessary whitespace and save it as a new list love_maybe_lines_stripped .

We cannot assign to the iteration variable of a for in loop. line is read-only. Try using a different variable in the above statement. Be sure to change it in the next line, too.

stripped_line = line.strip()

or something similar, so long as you don’t use, line =

I still receive the same error message :slightly_frowning_face:

Please post the code you have now.

love_maybe_lines = ['Always    ', '     in the middle of our bloodiest battles  ', 'you lay down your arms', '           like flowering mines    ','\n' ,'   to conquer me home.    ']

love_maybe_lines_stripped = []
for line in love_maybe_lines:
  new_line = line.strip(' ')
  love_maybe_lines_stripped.append(new_line)

#print(love_maybe_lines_stripped[3])
print(love_maybe_lines_stripped)

strip() defaults to a space character if none is specified. Also, don’t print anything, for now.

1 Like

Thanks a lot!!
it worked.

1 Like

Errata

“We cannot assign to the iteration variable…”, has been refuted. Thanks, @tgrtim for catching this.

There are some underlying quirks that need to be further explored, which would be an exercise in itself should someone wish to go down a rabbit hole for an hour or two.

Eg.

>>> for x in [1,2,3,4,5,6]:
	x = 7
	print (x)

	
7
7
7
7
7
7
>>> 

Anyone care to fill us in on the inner workings, here?

1 Like