I'm struggling with list comprehensions.
Basically I have a simple string:
string = "['a','b','c','d']"
Note, that the brackets,commas and quotation marks are part of the string.
What I need is a list1
with a,b,c,d as elements (so i need to get rid of the quotation marks, the commas and brackets.)
for entry in string:
list1 = [x.lstrip(" ' ") for x in string.split(',')]
list2 = [x.strip(" ' ") for x in list1]
This does not work at all. list1 gets created without the beginning "'"
, but when I try to print out list2 the quotations are there again. I did not even start dealing with the brackets.
Is there a nice way to get my list?