I currently have two lists. One contains two anchor elements, both contain the same href, but different text:
list1 = [<a href="link1">'text1'</a>, <a href="link1">'text2'</a>, 
         <a href="link2"><a href="link2"><span class="flagicon">
         <img Img stuff/></span>'text3'</a>, <a href="link2">'text4'</a>]
From this list I have managed to obtain the href links, and then I removed all duplicates. Since there were two href links, and they were the same, one of them was removed. Now my list with unique href links is:
list2 = ['link1','link2']
Now comes the tricky part. I want to use the unique href from my second list, to find the corresponding text in my first list but only once. I used this example to extract only unique href elements while preserving order. I also want to use that to obtain the text belonging to a unique hreffrom list1.
seen_text = set()
seen_text_add = seen_text.add
unique_text = [x.text for x in list1 if list2 in x and not (x in seen or seen_add(x))]
But this just returns an empty list. Can this be done?
EDIT: My expected result is unique_text =['text1','text3']
 
    