collection data types calculate( ( calculate(*tcalculate(*range( )in all three callsfour arguments are passed the second call unpacks -tupleand the third call unpacks the iterator returned by the range(function we will now look at small but complete program to consolidate some of the things we have covered so farand for the first time to explicitly write to file the generate_test_names py program reads in file of forenames and file of surnamescreating two listsand then creates the file test-names txt and writes random names into it we will use the random choice(function which takes random item from sequenceso it is possible that some duplicate names might occur first we'll look at the function that returns the lists of namesand then we will look at the rest of the program def get_forenames_and_surnames()forenames [surnames [for namesfilename in ((forenames"data/forenames txt")(surnames"data/surnames txt"))for name in open(filenameencoding="utf ")names append(name rstrip()return forenamessurnames tuple unpacking in the outer for in loopwe iterate over two -tuplesunpacking each -tuple into two variables even though the two lists might be quite largereturning them from function is efficient because python uses object referencesso the only thing that is really returned is tuple of two object references inside python programs it is convenient to always use unix-style pathssince they can be typed without the need for escapingand they work on all platforms (including windowsif we have path we want to present to the user insayvariable pathwe can always import the os module and call path replace("/"os septo replace forward slashes with the platform-specific directory separator forenamessurnames get_forenames_and_surnames(fh open("test-names txt"" "encoding="utf "for in range( )line "{ { }\nformat(random choice(forenames)random choice(surnames)fh write(line