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.
This, like it sounds, just takes all the elements of the list and joins them with
', '
.Here is a simple one.
the star unpacks the list and return every element in the list.
This is what you need
There are two answers , First is use 'sep' setting
The other is below
General solution, works on arrays of non-strings:
You need to loop through the list and use
end=" "
to keep it on one line