Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a list to a comma separated string?

Using a for loop I get the data:

58738121385139B
9135A4251EF0
2B631B53C383

I’m trying to get this data into one line separated by commas using

a = ', '.join(b);

but I get a comma after every character 5,8,7,3,8,1,2,1…
Please tell me how to get data 58738121385139B,9135A4251EF0,2B631B53C383 of this type.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  • depends on your result and description, I guess your code is something like:
b = """58738121385139B
9135A4251EF0
2B631B53C383"""
print(', '.join(b))
result:
5, 8, 7, 3, 8, 1, 2, 1, 3, 8, 5, 1, 3, 9, B, 
, 9, 1, 3, 5, A, 4, 2, 5, 1, E, F, 0, 
, 2, B, 6, 3, 1, B, 5, 3, C, 3, 8, 3
  • you should use split to achieve it
print(', '.join(b.split("\n")))
result:
58738121385139B, 9135A4251EF0, 2B631B53C383
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading