I have the following piece of code. Line 1 is a container (for simplicity, one can think of it as a list of elements e1, e2, ..., en). Now there is a function function_fun which takes as input an element ei and returns a list of elements. So finally we need to recursively keep processing elements from container and apply function_fun to get new elements such that the container satisfies some_property. Is this a general paradigm, and is there any faster way to do this?
1. container = [e1, e2, ..., en]
2. while (!some_property(container))
3. temp_container = []
4. for e in container
5. ttemp_container = function_fun(e)
5. temp_container = temp_container + ttemp_container
6. container = temp_container
7. return container
If someone wants a concrete example of this, then let's say we want to generate all binary strings of length n. Here is how we will implement it here:
1. container = ["0","1"]
2. while (len(container[0])!=n)
3. temp_container = []
4. for e in container
5. ttemp_container = [e+"0", e+"1"]
5. temp_container = temp_container + ttemp_container
6. container = temp_container
7. return container