set is arbitrarily extensible with functionsmodulesand classes to illustratehere are some of the same operations coded in more mnemonic fashion with the dictionaryrecord module we wrote earlierfrom makedicts import makedicts recs makedicts(curs"select from people where job 'devel'"print(len(recs)recs[ ] {'pay' 'job''devel''name''bob'print([rec['name'for rec in recs]['bob''ann''kim'print(sum(rec['pay'for rec in recs) avg sum(rec['pay'for rec in recslen(recsprint([rec['name'for rec in recs if rec['pay'avg]['kim'print([rec['name'for rec in recs if rec['pay'>avg]['bob''kim'similarlypython' set object type provides operations such as intersectionunionand difference which can serve as alternatives to other sql database operations (in the interest of spacewe'll leave their exploration as suggested side tripfor more advanced database extensionssee the sql-related tools available for python in the third-party domain for examplea variety of packages add an oop flavor to the db api--the orms we'll explore near the end of this sql utility scripts at this point in our sql db api tourwe've started to stretch the interactive prompt to its breaking point--we wind up retyping the same boilerplate code again every time we start session and every time we run test moreoverthe code we're writing is substantial enough to be reused in other programs let' wrap up by transforming our code into reusable scripts that automate tasks and support reuse to illustrate more of the power of the python/sql mixthis section presents handful of utility scripts that perform common tasks--the sorts of things you' otherwise have to recode often during development as an added bonusmost of these files are both command-line utilities and modules of functions that can be imported and called from other programs most of the scripts in this section also allow database file name to be passed in on the command linethis allows us to use different databases for different purposes during development--changes in one won' impact others table load scripts let' take quick look at code firstbefore seeing it in actionfeel free to skip ahead to correlate the code here with its behavior as first (and less than idealstepexample - shows simple way to script-ify the table-loading logic of the prior section sql database interfaces