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.

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']]

Leave a Reply