Sobes.tech
Middle+

Write a function that takes a list of numbers as input and returns a new list containing only the unique elements of the original list, maintaining their order.

sobes.tech AI

Answer from AI

python def unique_preserve_order(lst): seen = set() result = [] for item in lst: if item not in seen: seen.add(item) result.append(item) return result

Example usage:

print(unique_preserve_order([1, 2, 2, 3, 4, 3, 5])) # Will output [1, 2, 3, 4, 5]