fork(8) download
  1. from ast import literal_eval
  2. import re
  3.  
  4. def str_diff_parse(str_diff):
  5. return [tuple(literal_eval(y) for y in re.findall(r"\[('?\w+'?)\]", x)) for x in str_diff]
  6.  
  7.  
  8. added = {'root[2]': {3: {'age': 60, 'name': 'foobar'}}}
  9. updated = {"root[1][2]['age']": {'new_value': 90, 'old_value': 40}}
  10.  
  11. list_indexes_added = str_diff_parse(added)
  12. list_indexes_updated = str_diff_parse(updated)
  13.  
  14. print(list_indexes_added)
  15. print(list_indexes_updated)
Success #stdin #stdout 0s 9128KB
stdin
Standard input is empty
stdout
[(2,)]
[(1, 2, 'age')]