I have a list in Python e.g.
JavaScript
x
2
1
names = ["Sam", "Peter", "James", "Julian", "Ann"]
2
I want to print the array in a single line without the normal ” []
JavaScript
1
3
1
names = ["Sam", "Peter", "James", "Julian", "Ann"]
2
print (names)
3
Will give the output as;
JavaScript
1
2
1
["Sam", "Peter", "James", "Julian", "Ann"]
2
That is not the format I want instead I want it to be like this;
JavaScript
1
2
1
Sam, Peter, James, Julian, Ann
2
Note: It must be in a single row.
Advertisement
Answer
JavaScript
1
2
1
print(', '.join(names))
2
This, like it sounds, just takes all the elements of the list and joins them with ', '
.