Skip to content

Remove duplicates

Python nested loops

Flowchart (ISO 5807)

YesNoYesNoStartInput aresult = []x ∈ afound = Falsey ∈ resulty = xfound = Truenot foundresult.append(x)Return resultEndFigure 1 — remove_duplicates

Source code

Python
def remove_duplicates(a):
    result = []
    for x in a:
        found = False
        for y in result:
            if y == x:
                found = True
        if not found:
            result.append(x)
    return result

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
nested loops
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples