9.9 Writing recursive generator functions with the yield from statement
Many algorithms can be expressed neatly as recursions. In the Designing recursive functions around Python’s stack limits recipe, we looked at some recursive functions that could be optimized to reduce the number of function calls.
When we look at some data structures, we see that they involve recursion. In particular, JSON documents (as well as XML and HTML documents) can have a recursive structure. A JSON document is a complex object that can contain other complex objects within it.
In many cases, there are advantages to using generators for processing these kinds of structures. In this recipe, we’ll look at ways to handle recursive data structures with generator functions.
9.9.1 Getting ready
In this recipe, we’ll look at a way to search for all matching values in a complex, recursive data structure. When working with complex JSON documents...