Reputation: 39
I have this:
l_string = """[[-0.5, '#572fa5', 1], [-0.25, "#70339b", 1], [0.2, "#883691", 0.3], [0.5, "#b83d7e", 1], ["#e9446a", 1]]"""
and I want:
l = [[-0.5, '#572fa5', 1], [-0.25, "#70339b", 1], [0.2, "#883691", 0.3], [0.5, "#b83d7e", 1], [1, "#e9446a", 1]]
How can I convert it?
Upvotes: 3
Views: 71
Reputation: 5223
You need to use eval()
to parse the string to a valid Python list:
l_string = """[[-0.5, '#572fa5', 1], [-0.25, "#70339b", 1], [0.2, "#883691", 0.3], [0.5, "#b83d7e", 1], ["#e9446a", 1]]"""
l_string = eval(l_string)
print(l_string)
Output:
[[-0.5, '#572fa5', 1], [-0.25, '#70339b', 1], [0.2, '#883691', 0.3], [0.5, '#b83d7e', 1], ['#e9446a', 1]]
Upvotes: 2