Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [] instead of [4, 5]

output to be [4,5]

def remove_duplicates(numbers):
    duplicate =[]
    for a in numbers:
        for b in duplicate:
            if numbers[a] not in duplicate[b]:
    return duplicate


why use a second loop?

this condition:

if numbers[a] not in duplicate[b]:

given both numbers[a] and duplicates[b] are integers, this won't work, given in can check if an integer is present in a list

this we can use, we can simply check if a is in duplicate

also, a contains values from the list, not indexes


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.