Print Delimited list

0 votes
Here is a Python code for printing a list of comma separated values:

for element in list:
    print element + ",",
 

What is the preferred method for printing such that a comma does not appear if element is the final element in the list.

For example

a = [1, 2, 3]
for element in a
  print str(element) +",",

output
1,2,3,
desired
1,2,3
Feb 28 in Python by ana1504.k
• 7,470 points
18 views

1 answer to this question.

0 votes
You can try the following and see if it works :

>>> ','.join(map(str,a))
'1,2,3'
answered Feb 28 by SDeb
• 12,360 points

Related Questions In Python

+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
16,405 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,710 points
57 views
0 votes
1 answer

print(instance(0).id) TypeError: 'list' object is not callable

Hey @Suraj, For me its working fine. ...READ MORE

answered Jan 18 in Python by Priyaj
• 56,160 points
121 views
0 votes
1 answer

Print a list in both ascending and descending order

You can use listName.sort(reverse=True). This will sort the ...READ MORE

answered Feb 6 in Python by Omkar
• 67,120 points
16 views
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 56,160 points
43 views
+1 vote
1 answer

Python: Print variable and string in same line

For a better understanding you can refer ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 56,160 points
78 views
0 votes
1 answer

How do I print this list vertically?

You can try the following code: myList = ...READ MORE

answered Apr 5 in Python by SDeb
• 12,360 points
40 views
0 votes
1 answer

Print C format in Python

For printf- style formatting and special case ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 12,360 points
30 views