Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lists and Dictionaries (6 points): WP1 Complete the implementation of max_repeat

ID: 3902188 • Letter: L

Question

Lists and Dictionaries (6 points): WP1 Complete the implementation of max_repeat_counts, which takes a non-empty list and returns a dictionary containing a key for each element in the list, with a value corresponding to the maximum number of times the element repeats (in succession) E.g., max_repeat_counts([1, 2, 2, 2, 2]) returns t1: 1, 2: 4) E.?., max-repeat-counts([3, 3, 4, 4, 3, 4, 4, 4]) returns {3: 2, 4: 3} Insertion Sort (6 points) Consider the following reversed insertion sort implementation which prints the contents of the list at the start of each inner iteration: def rev_insertion_sort (lst) for i in range(1, len (1st)): for j in range(i, 0, 1): print (1st) # print list contents if lstjl lst [j-1: 1st [j-11, lstljl lst[jl, lst[j-1] else break WP2 Show the list contents, in order, displayed by all calls to print when rev_insertion_sort is called with the input list [2, 1, 3, 4, 5]. The first output is already filled in for you you may not need all lines

Explanation / Answer

def max_repeat_counts(lst): d = {} for value in lst: if value not in d: d[value] = 0 d[value] += 1 return d

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote