we see lazy evaluation used in many of python' libraries for examplethe dictionary class supports methods keys)values)and items)which respectively produce "viewof all keysvaluesor (key,valuepairs within dictionary none of these methods produces an explicit list of results insteadthe views that are produced are iterable objects based upon the actual contents of the dictionary an explicit list of values from such an iteration can be immediately constructed by calling the list class constructor with the iteration as parameter for examplethe syntax list(range( )produces list instance with values from to while the syntax list( values)produces list that has elements based upon the current values of dictionary we can similarly construct tuple or set instance based upon given iterable generators in section we will explain how to define class whose instances serve as iterators howeverthe most convenient technique for creating iterators in python is through the use of generators generator is implemented with syntax that is very similar to functionbut instead of returning valuesa yield statement is executed to indicate each element of the series as an exampleconsider the goal of determining all factors of positive integer for examplethe number has factors traditional function might produce and return list containing all factorsimplemented asdef factors( )results for in range( , + )if = results append(kreturn results traditional function that computes factors store factors in new list divides evenlythus is factor add to the list of factors return the entire list in contrastan implementation of generator for computing those factors could be implemented as followsdef factors( )for in range( , + )if = yield generator that computes factors divides evenlythus is factor yield this factor as next result notice use of the keyword yield rather than return to indicate result this indicates to python that we are defining generatorrather than traditional function it is illegal to combine yield and return statements in the same implementationother than zero-argument return statement to cause generator to end its execution if programmer writes loop such as for factor in factors( ):an instance of our generator is created for each iteration of the looppython executes our procedure