Chantal111 Chantal111 - 6 months ago 10
Python Question

How do I make my list without brackets, commas, and have every element start on a new line?

I have a loop that creates a list of sentences and I want them to print like this (all on different lines) :

Hi my name is joe
Hi my name is Sally
Hi my name is Bert


But they are printing like this instead:

['Hi my name is joe', 'Hi my name is Sally', 'Hi my name is Bert']


I am not too great at python so I would like a simple answer please. My loop looks a little like this:

sentence = "Hi my name is " + random.choice(name)
if name not in list:
list.append(sentence)

Answer

If your list is like this:

list = ['Hi my name is joe', 'Hi my name is Sally', 'Hi my name is Bert']

You would then simply do this:

for a in list: print(a)

Which would output this:

Hi my name is joe
Hi my name is Sally
Hi my name is Bert
Comments