elements sort(key=lambda ( [ ] [ ])here the key function is lambda ( [ ] [ ]with being each -tuple element in the list the parentheses around the lambda expression are required when the expression is tuple and the lambda function is created as function' argument we could use slicing to achieve the same effectelements sort(key=lambda ee[ : ] slightly more elaborate version gives us sorting in case-insensitive namenumber orderelements sort(key=lambda ( [ lower() [ ])here are two equivalent ways to create function that calculates the area of triangle using the conventional base height formulaarea lambda bh def area(bh)return we can call area( )whether we created the function using lambda expression or using def statementand the result will be the same default dictionaries another neat use of lambda functions is when we want to create default dictionaries recall from the previous that if we access default dictionary using nonexistent keya suitable item is created with the given key and with default value here are few examplesminus_one_dict collections defaultdict(lambda- point_zero_dict collections defaultdict(lambda( )message_dict collections defaultdict(lambda"no message available"if we access the minus_one_dict with nonexistent keya new item will be created with the given key and with value of - similarly for the point_zero_dict where the value will be the tuple ( )and for the message_dict where the value will be the "no message availablestring assertions |what happens if function receives arguments with invalid datawhat happens if we make mistake in the implementation of an algorithm and perform an incorrect computationthe worst thing that can happen is that the program executes without any (apparentproblem and no one is any the wiser one way to help avoid such insidious problems is to write tests--something we will briefly look at in another way is to state the preconditions and postconditions and to indicate an error if any of these are not met ideallywe should use tests and also state preconditions and postconditions