+ 3
Is there any way to typecast complex string to list?
Example. m_list = "[di1,di2,di3]" result = [di1,di2,di3] for complex data strings like list of lists using built in Python libraries.
3 Antworten
+ 5
Not pure typecast.
Split is powerfull to split text into lists.
m_list = "[1, 2, 3]"
m = [int(i) for i in m_list[1:-1].split(',')]
print(m)
+ 5
m_list = "[1, 2, 3]"
m = eval(m_list)
print(m)
+ 1
Use string replace and split methods. You can string string-methods together to make a one-liner. (hope that makes sense).
You can also use the "re" module (regular expression).