fork download
  1. import re
  2. from itertools import count
  3.  
  4. str1 = "[2.4],[5],[2.54],[4],[3.36],[4.46],[3.36],[4],[3.63],[4.86],[4],[4.63]"
  5. # => "[2.4,5],[2.54,4],[3.36,4.46],[3.36,4],[3.63,4.86],[4,4.63]"
  6. c = count(0)
  7. print( re.sub(r"],\[", lambda x: "," if next(c) % 2 == 0 else x.group(), str1) )
Success #stdin #stdout 0.03s 9488KB
stdin
Standard input is empty
stdout
[2.4,5],[2.54,4],[3.36,4.46],[3.36,4],[3.63,4.86],[4,4.63]