How to remove square brackets from list in Python?

Gregor Gajič picture Gregor Gajič · Nov 3, 2012 · Viewed 230.6k times · Source
LIST = ['Python','problem','whatever']
print(LIST)

When I run this program I get

[Python, problem, whatever]

Is it possible to remove that square brackets from output?

Answer

Sebastian Paaske Tørholm picture Sebastian Paaske Tørholm · Nov 3, 2012

You could convert it to a string instead of printing the list directly:

print(", ".join(LIST))

If the elements in the list aren't strings, you can convert them to string using either repr (if you want quotes around strings) or str (if you don't), like so:

LIST = [1, "foo", 3.5, { "hello": "bye" }]
print( ", ".join( repr(e) for e in LIST ) )

Which gives the output:

1, 'foo', 3.5, {'hello': 'bye'}