Q:

How can I return unique results from a python list in django using beautifulsoup

I am trying to return unique results from a list using beautifulsoup4 in Django. I tried doing it like this in my views.py:
 links = []

myset = set(links)

for link in soup.find_all('a', {"data-page": "1"}):
    links.append((
        link.text,
        link.get('href'))
    )

#links = soup.find_all("a")

title = "<h1>Scrape</h1>"
context = {
    "site": "http://www.vladtv.com",
    "title": title,
    "myset": myset,
}
return render(request, "posts/display_soup.html", context)

and in my template.html
{% block content %}
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
    <p>{{ title | safe}}</p>

    {% for text, href in links %}
        <a href="{{ site }}{{ href }}" class="thumbnail" >{{ text }}</a><br>
    {% endfor %}
</div>
 </div>
{% endblock %}

and again like this
{% block content %}
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
    <p>{{ title | safe}}</p>

    {% for text, href in myset %}
        <a href="{{ site }}{{ href }}" class="thumbnail" >{{ text }}</a><br>
    {% endfor %}
</div>
 </div>
{% endblock %}

and like this
{% block content %}
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
    <p>{{ title | safe}}</p>

    {% for text, href in myset.links %}
        <a href="{{ site }}{{ href }}" class="thumbnail" >{{ text }}</a><br>
    {% endfor %}
</div>
 </div>
{% endblock %}

but none of these seem to work. I think it has something to do with me using set() But I have not figured out

A:

This:
myset = set(links)

needs to go below your code where you gather your links:
for link in soup.find_all('a', {"data-page": "1"}):
    links.append((
        link.text,
        link.get('href'))
    )

