elif action =" "list_dvds(dbelif action =" "remove_dvd(dbelif action =" "import_(dbelif action =" "export(dbelif action =" "quit(db functions dict( =add_dvde=edit_dvdl=list_dvdsr=remove_dvdi=import_x=exportq=quitfunctions[action](dbthe choice is held as one-character string in the action variableand the database to be used is held in the db variable the import_(function has trailing underscore to keep it distinct from the built-in import statement in the right-hand code snippet we create dictionary whose keys are the valid menu choicesand whose values are function references in the second statement we retrieve the function reference corresponding to the given action and call the function referred to using the call operator()and in this examplepassing the db argument not only is the code on the right-hand side much shorter than the code on the leftbut also it can scale (have far more dictionary itemswithout affecting its performanceunlike the left-hand code whose speed depends on how many elifs must be tested to find the appropriate function to call the convert-incidents py program from the preceding uses this technique in its import_(methodas this extract from the method showscall {(aix""dom")self import_xml_dom(aix""etree")self import_xml_etree(aix""sax")self import_xml_sax(ait""manual")self import_text_manual(ait""regex")self import_text_regex(aib"none)self import_binary(aip"none)self import_pickleresult call[extensionreader](filenamethe complete method is lines longthe extension parameter is computed in the methodand the reader is passed in the dictionary keys are -tuplesand the values are methods if we had used if statementsthe code would be lines longand would not scale as well generator expressions and functions generator functions |back in we introduced generator functions and methods it is also possible to create generator expressions these are syntactically almost