fork(1) download
  1. import re, ast
  2. s="""test1 21;
  3. test2 22;
  4. test3 [ 23 ];"""
  5. output = [ast.literal_eval("[" + re.sub(r'\s*,\s*(?=])', '', re.sub(r"\w+", r"'\g<0>',", " ".join(x.split())).strip(',;')) + "]") for x in s.split('\n')]
  6. print(output)
Success #stdin #stdout 0.03s 10112KB
stdin
Standard input is empty
stdout
[['test1', '21'], ['test2', '22'], ['test3', ['23']]]