Remove duplicates · Xóa trùng lặp
Remove duplicates
Return a new list that keeps each value only once, in the order it first appeared: [1, 1, 2, 3, 3, 1] becomes [1, 2, 3].
A set answers "have I seen this already?" in one fast step. Keep a set of seen values and a list for the result, and only append a value the first time you meet it.
Xóa trùng lặp
Trả về một danh sách mới giữ lại mỗi giá trị chỉ một lần, theo thứ tự nó xuất hiện lần đầu: [1, 1, 2, 3, 3, 1] trở thành [1, 2, 3].
Một set trả lời "Tôi đã thấy cái này chưa?" trong một bước nhanh. Giữ một set các giá trị đã gặp và một danh sách cho kết quả, và chỉ thêm vào một giá trị lần đầu tiên bạn gặp nó.
Write dedupe(xs) that returns a new list with duplicates removed, keeping the order of first appearance. · Viết dedupe(xs) trả về danh sách mới với các trùng lặp bị xóa, giữ nguyên thứ tự xuất hiện đầu tiên.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.