What The Heck Is Yield For?
·
·
A question came up recently about the purpose of the Python yield expression and when you should use it. Consider this silly function that computes a list of integers from 0 to 99 raised to the given exponent: When called, this function runs thru all 100 integers in the range computing each term and then returns the list to the caller. We can sum the list and get the expected result. This function will return to the caller pretty quickly, however when the number of items being processed grows much larger, say two billion, then the delay between calling the function and…