← All examples

Remove duplicates

Python Algorithms

nested loops

Flowchart (ISO 5807)

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

Source code

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