5.32. Functions and Lists Write Code QuestionsΒΆ
Write a function called
average_of_num_list
that takes in a parameternum_list
and returns the average of all the numbers in num_list. For example,average_of_num_list([0, 20.8, 80, 5])
would return26.45
.Write a function called
average_of_num_list
that takes in a parameternum_list
and returns the average of all the numbers in num_list. For example,average_of_num_list([0, 20.8, 80, 5])
would return26.45
.-
Write a function called
names
that takes in a parametername_list
and returns an alphabetically sortedname_list
. For example,names(['Susan', 'Sara', 'Sammy', 'Sarah'])
would return['Sammy', 'Sara', 'Sarah', 'Susan']
. Write a function called
remove_min_value
that takes in a parameternum_list
and returns anum_list
without the minimum value fromnum_list
. For example,remove_min_value([20, 4, 1203, 7482, 3])
would return[20, 4, 1203, 7482]
.Write a function called
remove_min_value
that takes in a parameternum_list
and returns anum_list
without the minimum value fromnum_list
. For example,remove_min_value([20, 4, 1203, 7482, 3])
would return[20, 4, 1203, 7482]
.-
Write a function called
range_given_list
that takes in a parameterlist_of_nums
and returns the range (max value - min value) of the values. Try using the sort method and indexing. For examplerange_given_list([20, 100, 2000, 15, 3, 12])
would return1997
. Write a function called
remove_indices_after_first_max_value
that takes in a parameternum_list
and returns anew_num_list
with values up to the max value of the list. For example,remove_indices_after_first_max_value([200, 10, 5, 200])
would return[5, 10, 5, 200]
.Write a function called
remove_indices_after_first_max_value
that takes in a parameternum_list
and returns anew_num_list
with values up to the max value of the list. For example,remove_indices_after_first_max_value([200, 10, 5, 200])
would return[5, 10, 5, 200]
.-
Write a function called
transform_and_combine
that takes in two parameters,list_one
, which must have at least one element, andlist_two
. Remove the last element fromlist_one
, then reverse the list. Sortlist_two
, then extendlist_two
withlist_one
, and returnlist_two
. Hint: Use list methods (e.g., pop, sort, append, reverse, and extend). For example,transform_and_combine([5, 20, 3, 15, 200, 0, 17], ['Hello', 'Bye', 'How are you?'])
would return['Bye', 'Hello', 'How are you?', 0, 200, 15, 3, 20, 5]
.