compares the running time of list compared to generator import time #generator function creates an iterator of odd numbers between and def oddgen(nm)while myield + #builds list of odd numbers between and def oddlst( , )lst=[while <mlst append(nn += return lst #the time it takes to perform sum on an iterator =time time(sum(oddgen( , )print("time to sum an iterator% (time time( )#the time it takes to build and sum list =time time(sum(oddlst( , )print("time to build and sum list% (time time( )this prints out the followingas we can seebuilding list to do this calculation takes significantly longer the performance improvement as result of using generators is because the values are generated on demandrather than saved as list in memory calculation can begin before all the elements have been generated and elements are generated only when they are needed in the preceding examplethe sum method loads each number into memory when it is needed for the calculation this is achieved by the generator object repeatedly calling the __next__(special method generators never return value other than none typicallygenerator objects are used in for loops for examplewe can make use of the oddcount generator function created in the preceding code to print out odd integers between and for in oddcount( , ):print(