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
• 6,150 points
14 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
You can try the following and see if it works :

>>> ','.join(map(str,a))
'1,2,3'
answered Feb 28 by SDeb
• 9,740 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
12,233 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
38 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,120 points
86 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
• 66,050 points
12 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,120 points
29 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,120 points
60 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
• 9,740 points
35 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
• 9,740 points
26 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.