Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python add quotes to all elements in list?

Tags:

python

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"
like image 527
a1234 Avatar asked Feb 14 '26 15:02

a1234


1 Answers

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

like image 191
Patrick Haugh Avatar answered Feb 16 '26 08:02

Patrick Haugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!