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

Python: how to form the correct list

This is my data looks like

my_list = [('Australia',), ('Europe',)]

I need to remove the comma "," after every element.

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

new_list = [('Australia'), ('Europe')]

I can achieve this using a loop and extracting one element at a time and replacing it. Is there a better way to achieve the same. Thank you

>Solution :

That comma, indicates that you have a tuple. If you want to not have that comma, you can change tuples to lists:

new_list = [list(country) for country in my_list]

It gives You:

[['Australia'], ['Europe']]
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