lundi 31 août 2020

Creating a new List out of a List but without dublicate items?

i have a List

carner_list = ['<a href="/lyric/34808442/Loyle+Carner/Damselfly">Damselfly</a>',
 '<a href="/lyric/37311114/Loyle+Carner/Damselfly">Damselfly</a>',
 '<a href="/lyric/37360958/Loyle+Carner/Damselfly">Damselfly</a>',
 '<a href="/lyric/33661937/Loyle+Carner/The+Isle+of+Arran">The Isle of Arran</a>',
 '<a href="/lyric/33661936/Loyle+Carner/Mean+It+in+the+Morning">Mean It in the Morning</a>']

Now i want to get rid of the dublicated items. The Problem is, the items that are double are only different from each other at a specific point in the string, i[38:].

My idea was to create a for loop:

new_list = []
for i in carner_list:
       if i[38:] in new_list:
           print("found")
       else:
           new_list = new_list + [i]
           print("not")

But this is not working.

Is something in the syntax wrong or am i completely on the wrong track?

Best Russell

Aucun commentaire:

Enregistrer un commentaire