Posts: 1,298
Threads: 38
Joined: Sep 2016
Is there a way to remove apostrophes in list so that this:
a_list = ['mary', 'had', 'a', 'little', 'lamb']
becomes:
a_list = [mary, had, a, little, lamb]
Thank you
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 58
Threads: 10
Joined: Mar 2017
I'm sure that you have tried a number of options.
This may not give you the complete solution but what about, rebuilding the list along this idea:
b_list = a_list[0]+" "+a_list[1]+" "+a_list[2]
etc.
Giving you a result of:
b_list = mary had a little lamb
Obviously you can add back any commas, but as my experience is python limited, I not sure of how to ensure that the b_list becomes a true list with [] etc.
Can you give us an idea of your reasons as this may help with a solution.
"The good thing about standards is that you have so many to choose from" Andy S. Tanenbaum
Posts: 1,298
Threads: 38
Joined: Sep 2016
Fair enough. In a previous post (
else-statement-not-executing) it was intimated that a preferred method within menus was the use of dictionaries. Which is fine, if the dictionary is hard coded, however, in my particular case, neither the 'key' nor the value are known in advance. As you say, every attempt I try always puts the 'value' back as a string.
It's not a deal breaker, as the 'eval' option mentioned in the previous post solves the problem, just wanted to know if it was possible.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 1,298
Threads: 38
Joined: Sep 2016
Duly noted, thank you. I'll give it a try.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition