I have the following
str = '[5.955894, 45.817792], [10.49238, 45.817792], [10.49238, 47.808381], [5.955894, 47.808381]'
I want to split it so that I have an array of strings like
['[5.955894, 45.817792]', '[10.49238, 45.817792]', ...]
So that the [...] objects are elements of the array. It is important that the enclosing [ and ] are included. I've come so far:
re.split('\D,\s\D', str)
But that gives me:
['[5.955894, 45.817792', '10.49238, 45.817792', '10.49238, 47.808381', '5.955894, 47.808381]']
Not really what I want.
eval('[' + str + ']')if it comes from trusted source. - nhahtdhevalwon't give what OP wants, but as a side note, there isast.literal_evalwhich would do the same thing asevalwithout the security implications. - mgilson