Prelab 5 Due: 8:00AM on 2021-10-15

Review lists

Review the class notes and examples from this week covering lists. In particular, recall there are built-in functions that apply to lists:

Furthermore, the Python documentation for lists includes links to operations and methods that apply to common sequence types and mutable sequence types including lists.

Practice with built-in functions and methods on lists

Answer these two questions on Gradescope

Question 1: Write a Python expression that sorts a list data in place. For example, if data were the list [45, 6.2, -3.5, 10] then after execution of your expression the list data would contain [-3.5, 6.2, 10, 45].

Question 2: Write a sequence of Python statements that given a non-empty list would return the middle value (not median!) in the list. For an odd number of list elements, this is the value at the middle position. For an even number of list elements, return the average of the two middle items. For example, if data=[35, 14, 10, 81, 40] then middle(data) would evaluate to 10. If data=[35, 14, 10, 81] then middle(data) would evaluate to 12, the average of 14 and 10. Your statements should complete the following function:

def middle(sequence):
    """
    Return middle value in non-empty sequence.
    
    Args:
        sequence: a sequence of values of any type, sorted or unsorted
        
    Return:
        The middle element if sequence has odd length, or the average
        of the two middle elements if sequence has even length
    """