# COMP 2800 - Spring 2024 - Assignment 1 # Complete all of the following functions. Currently they all just # 'pass' rather than explicitly return a value, which means that they # implicitly return None. They all include doctests, which you can # test by running this file as a script: python3 assign1.py # Feel free to add your own doctests. def sumFive(lst): """ Sum the first 5 elements of the list given. If the length of the list is less than 5, just sum as many elements as it has. If the length of the list is 0, the sum should be 0. >>> sumFive([2,4,6,8,10,12,14,16,18,20]) 30 >>> sumFive([5,12]) 17 >>> sumFive([]) 0 """ pass def middle(data, num): """ Returns a list of length num comprised of the 'middle' elements of data. If num is greater or equal to the length of data, all of data should be returned. >>> middle([1,2,3,4,5,6], 2) [3, 4] >>> middle([1,2,3,4,5,6], 0) [] >>> middle([1,2,3], 4) [1, 2, 3] >>> middle([1,2,3,4,5,6], 3) [3, 4, 5] """ pass def invertDict(d): """ Returns a new dictionary in which the keys and values are inverted. If d contains any values that appear for more than one key, then only the first occurance (in the normal iteration order) is added to the new dictionary >>> invertDict({}) {} >>> invertDict({'a': 1, 'b': 2, 'c': 3}) {1: 'a', 2: 'b', 3: 'c'} >>> invertDict({'a': 'y', 'b': 'z', 'c': 'y'}) {'y': 'a', 'z': 'b'} """ pass def secondLargest(values): """ Given a list of integers, return the number that is the second largest in the list >>> secondLargest([24, 12, 7, 41, 23, 8, 34, 18]) 34 """ pass if __name__ == '__main__': import doctest doctest.testmod()