Given the list
lst
of positive integers, associate the largest duplicated element with the variablemax_dup
. If the list contains no duplicates, associate -1 withmax_dup
.
I understand how to sort the list and how to find the max but I am having trouble figuring out how to keep only duplicates in the list.
All the research I have done has given me functions to import, while I want to code all of the parts.
max_dup=lst[0]
max_count = lst.count(lst[0])
for i in range(1,len.lst-1)
if lst.count(lst[i]) > max_count and lst[i] > max_dup:
max_dup = lst[i]
max_count = lst.count(lst(i))
if max_dup == 1:
max_dup = -1