Generation

generate functionFri, 19 May 2023

Escriba un programa en Python que acepte una lista y elimine sus elementos duplicados (solución). Entrada: [“this”, “is”, “a”, “real”, “real”, “real”, “story”] Salida: [“this”, “is”, “a”, “real”, “story”]

def remove_duplicates(values): output = [] seen = set() for value in values: # If value has not been encountered yet, # ... add it to both list and set. if value not in seen: output.append(value) seen.add(value) return output print(remove_duplicates([1, 2, 3, 3, 3, 3, 4, 5]))

Questions about programming?Chat with your personal AI assistant