Suppose I have an arbitrarily nested list in which some of the nested elements can be generators. For example:
nested_gens = [ [1, [2, [3, 4]]], [2, (map(int, '123'))], [3, (map(str, range(i+1)) for i in range(2))] ]
How can I recursively go through this structure and consume all the generator objects?
My desired output is:
[ [1, [2, [3, 4]]], [2, [1, 2, 3]], [3, [['0'], ['0', '1']]] ]
A solution to this question could be generalized for pickling objects that contain generators. All the answers I've found for dealing with TypeError: can't pickle generator objects
don't deal with nested generators.
#python