fork download
  1. def remove_duplicates(input_list):
  2. # Initialize an empty list to store the result
  3. result = []
  4. # Initialize an empty set to track seen elements
  5. seen = set()
  6.  
  7. # Iterate over each element in the input list
  8. for item in input_list:
  9. # If the item is not in the seen set, it's not a duplicate
  10. if item not in seen:
  11. # Add the item to the result list
  12. result.append(item)
  13. # Mark the item as seen by adding it to the set
  14. seen.add(item)
  15.  
  16. # Return the result list with duplicates removed
  17. return result
  18.  
  19. # Example usage
  20. print(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]
Success #stdin #stdout 0.01s 7296KB
stdin
Standard input is empty
stdout
[1, 2, 3, 4, 5]