I am trying to print each line into a list element.
Currently I have:
Variable = apple
ball
chart
desk
I want it into ['apple', 'ball', 'chart', 'desk']. I tried append and I get the error str object has no attribute append...
I think it is the inverse of How can I format a list to print each element on a separate line in python?
THis is the code I have so far:
for entry in variable.strip().split(","):
variable_final = entry.lstrip()
print variable_final
The above code prints out:
apple
ball
chart
desk
but when I do print [variable_final] it prints out each line as a list.
Note: I still cant figure out a way to do this. Eventually all I need to do is print these lines vertically. I had asked this question earlier but it was made duplicate... I cannot find a way to print multiple lines vertically or print multiple lists vertically...
a b c d
p a h e
p l a s
l l r k
e t