0

Here is my code

list = [1,2,3]
for i in list:
    print(i)

This is the output

1
2
3

What I'm looking for

1, 2, 3
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
Cristian
  • 155
  • 8

2 Answers2

0

If python 3 print(i, end =", ")

If python 2 append a comma to the print to escape the newline print(i),

Enigma
  • 373
  • 2
  • 10
0

A mixture of generators and join

lst = [1,2,3]
print(','.join(str(i) for i in lst))
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44