Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove duplicates in nested list with specified index

I want to remove the list which contains the maximum number( In this list 16)

Code sample

Lst = [["D",16],["B",10],["A",13],["B",16]]

required output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Lst =[["B",10],["A",13]]

>Solution :

Lst = [["D",16],["B",10],["A",13],["B",16]]

max_elem = -float("inf")

for element in Lst:
    if element[1] > max_elem:
        max_elem = element[1]

for i in reversed(range(len(Lst))):
    if Lst[i][1] == max_elem:
        Lst.pop(i)

print(Lst)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading