Remove duplicates · ลบ duplicate
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.
ลบค่าซ้ำ
return ลิสต์ใหม่ที่เก็บแต่ละค่าไว้เพียงครั้งเดียว ตามลำดับที่มัน ปรากฏครั้งแรก: [1, 1, 2, 3, 3, 1] กลายเป็น [1, 2, 3]
一个 set ตอบคำถาม "เคยเห็นสิ่งนี้ไหม?" ในขั้นตอนเดียวที่รวดเร็ว. Keep a set ของค่าที่เคยเห็นและลิสต์สำหรับผลลัพธ์, และ append ค่าเฉพาะครั้งแรกที่คุณพบมัน
Write dedupe(xs) that returns a new list with duplicates removed, keeping the order of first appearance. · เขียน dedupe(xs) ที่กลับค่า list ใหม่โดยไม่มี duplicate รักษาลำดับการปรากฏครั้งแรก
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่