Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. ['.Attributes[2]']['bestTime'] => Jun 25, 2018 6:00:00 AM
  2.  
  3. ['Attributes'][2]['bestTime'] => Jun 25, 2018 6:00:00 AM
  4.  
  5. str = {"lAttributes":[{"Identifier":{"newIdentifier":{"DDline":"BM","guideIdDate":"Jun 25, 2018 12:00:00 AM","guideNo":"MM","suffix":"A"},"origin":"FRY","destination":"DZ"},"guideOwner":"VX","guideRegistration":"DD","guideType":"44","bestaartureStatus":"S","bestaaTime":"Jun 25, 2018 6:00:00 AM","bestaaStatus":"S","bestaartureTime":"Jun 25, 2018 5:00:00 AM","compartments":[{"code":"DD","guideCapacity":8,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":10,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":32,"guideBooked":0,"guideForecast":0},{"code":"DD","guideCapacity":24,"guideBooked":0,"guideForecast":0}]}]}
  6.  
  7. list_k = ['w','r']
  8. def traverse(path, str):
  9. count = -1
  10. if isinstance(str, dict):
  11. d = str
  12. for k, v in d.items():
  13. if isinstance(v, dict):
  14. traverse(path + "." + k, v)
  15.  
  16. elif isinstance(v, list):
  17. traverse(path + "." + k, v)
  18.  
  19. else:
  20. if k in list_k:
  21. print("['"+path +"']"+ "['"+k+"']", "=>", v)
  22.  
  23. if isinstance(str, list):
  24. li = str
  25. for e in li:
  26. count += 1
  27. if isinstance(e, dict):
  28. traverse("{path}[{count}]".format(path=path, count=count), e)
  29. elif isinstance(e, list):
  30. traverse("{path}[{count}]".format(path=path, count=count), e)
  31. else:
  32. print("[{path}][{count}] => {e}".format(path=path, count=count, e=e))
Add Comment
Please, Sign In to add comment