s = "[[A, B],[E,R], [E,G]]"
Is there a built-in way to convert this string into an array? (s[][])
There is, but in your case it will assume A B E R G to be variables, is this the case?
If this is not the case you will need to do some extra formatting with the string.
This will work if the variables A B E R G are set:
s = eval(s)
If the letters need to be strings you will have to do some kind of regexp to replace all occurrences of chars with quoted chars.
eval, which may execute arbitrary code if s has been tampered with.If A B E R G are not variables but just a string then you can use the following code:
tmp = ''
for c in s:
if c.isalpha():
t+="'%s'"%c
else:
t+=c
eval(t) # will give you [['A', 'B'], ['E', 'R'], ['E', 'G']]
OR:(very ugly i know but don't beat me too much - just experementing)
evel(''.join(map(lambda x: s[x[0]] if not s[x[0]].isalpha() else "'%s'" % s[x[0]], enumerate(map(lambda c: c.isalpha(), s)))))