Remove_duplicates


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/4?curriculum_id=4f89dab3d788890003000096#

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]:
                duplicate.append(numbers[a])
    return duplicate

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/4?curriculum_id=4f89dab3d788890003000096#


#2

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


#3

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