fork download
  1. dct = {'person': {'in_dict': [1, 2, 3],
  2. 'after_list': {4, '5'},
  3. 'after_set': ('hello',)}}
  4.  
  5. new = {}
  6. for k,v in dct['person'].items():
  7. try:
  8. hash(v)
  9. new[k] = v
  10. except:
  11. hv = tuple(v)
  12. try:
  13. iter(hv)
  14. for item in hv:
  15. new[(item,hv)] = v
  16. except:
  17. new[k,v] = v
  18. print(new)
Success #stdin #stdout 0.02s 9076KB
stdin
Standard input is empty
stdout
{(1, (1, 2, 3)): [1, 2, 3], (2, (1, 2, 3)): [1, 2, 3], (3, (1, 2, 3)): [1, 2, 3], (4, (4, '5')): {4, '5'}, ('5', (4, '5')): {4, '5'}, 'after_set': ('hello',)}