def last_element(some_list): '''Return the last element of some_list''' if len(some_list) == 0: return None else: return some_list[-1] def second_largest(my_list): '''Return the second largest value in my_list Example: second_largest([3, 10, 2, 1]) should be 3 ''' copy_list = my_list.copy() copy_list.sort() # sort a copy of the last, not the original list return copy_list[-2] def last_three(some_string): '''Returns the last 3 characters of some_string Example: last_three('computer') should return 'ter' ''' return some_string[-3:] def print_squared_list(some_list): '''Print every element of some_list squared.''' for list_el in some_list: print(list_el ** 2) def print_negative_nums(some_list): '''Print only the negative elements of some_list. Example: print_negative_nums([5, -3, -7, 2]) should print -3 and -7''' for num in some_list: if num < 0: print(num) def get_negative_nums(some_list): '''Return a list of all the negative elements of some_list. Example: print_negative_nums([5, -3, -7, 2]) should return [-3, -7]''' negative_so_far = [] # make an empty list for num in some_list: if num < 0: negative_so_far.append(num) # after running the complete loop, return the result list return negative_so_far def list_length(some_list): '''Return the length of some_list without using len.''' count = 0 # running counter for element in some_list: count += 1 # after completion of the loop return count