Print list without brackets in a single row


I have a list in Python e.g.

names = ["Sam", "Peter", "James", "Julian", "Ann"]

I want to print the array in a single line without the normal " []

names = ["Sam", "Peter", "James", "Julian", "Ann"]
print (names)

Will give the output as;

["Sam", "Peter", "James", "Julian", "Ann"]

That is not the format I want instead I want it to be like this;

Sam, Peter, James, Julian, Ann

Note: It must be in a single row.

10/8/2016 11:26:00 AM

Accepted Answer

print(', '.join(names))

This, like it sounds, just takes all the elements of the list and joins them with ', '.

10/5/2018 2:51:03 PM

Here is a simple one.

names = ["Sam", "Peter", "James", "Julian", "Ann"]
print(*names, sep=", ")

the star unpacks the list and return every element in the list.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow