matrix {( ) ( ) herewe've used dictionary to represent three-dimensional array that is empty except for the two positions ( , , and ( , , the keys are tuples that record the coordinates of nonempty slots rather than allocating large and mostly empty threedimensional matrix to hold these valueswe can use simple two-item dictionary in this schemeaccessing an empty slot triggers nonexistent key exceptionas these slots are not physically storedmatrix[( , , )traceback (most recent call last)file ""line in keyerror( avoiding missing-key errors errors for nonexistent key fetches are common in sparse matrixesbut you probably won' want them to shut down your program there are at least three ways to fill in default value instead of getting such an error message--you can test for keys ahead of time in if statementsuse try statement to catch and recover from the exception explicitlyor simply use the dictionary get method shown earlier to provide default for keys that do not exist consider the first two of these previews for statement syntax we'll begin studying in if ( in matrixprint(matrix[( )]elseprint( tryprint(matrix[( )]except keyerrorprint( matrix get(( ) matrix get(( ) check for key before fetch see and for if/else try to index catch and recover see and for try/except existsfetch and return doesn' existuse default arg of thesethe get method is the most concise in terms of coding requirementsbut the if and try statements are much more general in scopeagainmore on these starting in nesting in dictionaries as you can seedictionaries can play many roles in python in generalthey can replace search data structures (because indexing by key is search operationand can represent many types of structured information for exampledictionaries are one of many ways lists and dictionaries