re: Are there functions similar to Ruby's `dig` in other languages? VIEW POST


For Python, glom is a great package for this sort of nested data access. The happy path from the intro docs looks like this:

from glom import glom

target = {'a': {'b': {'c': 'd'}}}
glom(target, 'a.b.c')  # returns 'd'

That 'a.b.c' bit is a simple glom specifier, but it can get much wilder! Glom provides more advanced specifiers for features like:

  • Null coalescing behavior
  • Validation
  • Debugging/inspection

And you can always plug in your own code or extend glom even further. Simple to get started, but a long fun road to travel from there!

code of conduct - report abuse