Remove duplicates / not working with empty list


#1


https://www.codecademy.com/fr/courses/python-intermediate-fr-FR-py0yl/2/4?curriculum_id=5370f030fed2a866a2000001#

Oups, merci de réessayer. Votre fonction a échoué sur [] comme entrée car votre fonction renvoie une erreur "global name 'liste' is not defined".

Hello don't understand why empty list return this error

def supprimer_doublons(liste):

    new=[]
    if liste:
        for x in liste:
            if x not in new:
                new.append(x)
    return new


#2

Bonjour maximeparisestmagiqu,

Ce n'est pas nécessaire ...

if liste:

Il y a un bug dans l'exercice.

Ajoutez ceci à votre code ...

class str:
    pass

#3

Try:

def remove_duplicates(numbers):
final = []
for i in numbers:
if i not in final:
final.append(i)
return final


#4

Hi @chipblaster59046,

Unfortunately, that code will not pass the submission correctness test (SCT) for the French version of the exercise, which is what @maximeparisestmagiqu was asking about.

Some reasons for this are:

  • The French version of the exercise requires a different name for the function (supprimer_doublons).
  • There is a bug in the submission correctness test (SCT) for the French version of the exercise, and this requires a workaround (code de déblocage) in order for the submitted code to pass.

#5