1 | initial version |
Alternatively, an uglier but safer method (preventing possible evaluation of malicious code),
my_string = '[[sqrt(2),sqrt(3)], [sqrt(5),sqrt(7)]]'
matrix(filter(None, [map(SR, filter(lambda s:not s.strip() == '', l)) for l in map(lambda x:x.split(','), my_string.replace('[', '').split(']'))]))
Replace SR
with whatever ring/field you want to coerce the entries into.