functions and functional programming unlike list comprehensiona generator expression does not actually create list or immediately evaluate the expression inside the parentheses insteadit creates generator object that produces the values on demand via iteration here' an examplea [ ( * for in ab next( next( the difference between list and generator expressions is importantbut subtle with list comprehensionpython actually creates list that contains the resulting data with generator expressionpython creates generator that merely knows how to produce data on demand in certain applicationsthis can greatly improve performance and memory use here' an exampleread file open("data txt"lines ( strip(for in fopen file read linesstrip trailing/leading whitespace comments ( for in lines if [ ='#'all comments for in commentsprint(cin this examplethe generator expression that extracts lines and strips whitespace does not actually read the entire file into memory the same is true of the expression that extracts comments insteadthe lines of the file are actually read when the program starts iterating in the for loop that follows during this iterationthe lines of the file are produced upon demand and filtered accordingly in factat no time will the entire file be loaded into memory during this process thereforethis would be highly efficient way to extract comments from gigabyte-sized python source file unlike list comprehensiona generator expression does not create an object that works like sequence it can' be indexedand none of the usual list operations will work (for exampleappend()howevera generator expression can be converted into list using the built-in list(functionclist list(commentsdeclarative programming list comprehensions and generator expressions are strongly tied to operations found in declarative languages in factthe origin of these features is loosely derived from ideas in mathematical set theory for examplewhen you write statement such as [ * for in if ]it' somewhat similar to specifying set such as oeax instead of writing programs that manually iterate over datayou can use these declarative features to structure programs as series of computations that simply operate on all of the data all at once for examplesuppose you had file "portfolio txtcontaining stock portfolio data like thisf lib fl ff