a1234
a1234

Reputation: 821

Python add quotes to all elements in list?

I have a several list with in a dictionary. How do I add quotes around every element in each list?

native_american={
"A2" : ["Native, Eskimo Volodko, Apache, Mexico, Central America, Guarani, Rio das Cobras, Katuana, Poturujara, Surui, Waiwai, Yanomama, Zoro, Arsario, Cayapa, Kogui, Inupiat, Lauricocha"],
"A2a" : ["Aleut, Eskimo, Apache, Siberian Eskimo, Chukchi, Dogrib, Innuit, Naukan Na-Dene, Chukchis, Athabaskan"],
"A2b" : ["Paleo Eskimo"]}

I would like it to look like....

"Native", "Eskimo Volodko", "Apache", "Mexico"

Upvotes: 3

Views: 4953

Answers (2)

Patrick Haugh
Patrick Haugh

Reputation: 61032

native_american = {key: value[0].split(',') for key, value in native_american.items()}

What you have at the moment is a list of one long string. This splits it into a list of many smaller strings

Upvotes: 4

Philip Tzou
Philip Tzou

Reputation: 6458

Do you mean something like "Native", "Eskimo Volodko", "Apache"?

If so: [item.strip() for item in list.split(',')]

Upvotes: 0

Related Questions