Filed under python

Using Python Generators (a recursion example)

Recursion is a powerful programming tool, but also a tricky one. Knowing what’s going on in a recursive function at the various frame levels can be difficult which makes debugging recursive functions challenging. So below is a code snippet that uses recursion to find the largest odd factor of an input integer, and returns the … Continue reading

Python Generators vs. Closures

Generators and closures are two special function types that can come in handy under the right circumstances. To illustrate the basic usage and differences I will use some example code.   # python def inc_by_10_generator():     # returns infinite series of 10’s starting at 10 – recalls position     i = 10     while True: … Continue reading