python – Print list without brackets in a single row

python – Print list without brackets in a single row

print(, .join(names))

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

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.

python – Print list without brackets in a single row

General solution, works on arrays of non-strings:

>>> print str(names)[1:-1]
Sam, Peter, James, Julian, Ann

Leave a Reply

Your email address will not be published. Required fields are marked *