-4

Given the list lst of positive integers, associate the largest duplicated element with the variable max_dup. If the list contains no duplicates, associate -1 with max_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
Sheila Evans
  • 9
  • 1
  • 6

1 Answers1

0

I hope this could help you

a = [7, 4, 7, 2, 3, 7, 3]

a.sort() max_dup = 1 max_ele = a[0] for i in range(len(a) - 1): if a[i] == a[i + 1]: max_dup += 1 else: max_dup = 1 max_ele = a[i + 1] print(max_dup) print(max_ele)

sorry about formatting

Grak T
  • 26
  • 4