Remove duplicates · 重複を削除
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.
重複を削除
各値が最初に出現した順序で重複なく残る新しいリストを返します: [1, 1, 2, 3, 3, 1] は [1, 2, 3] に変換されます。
set は「すでに見たことがあるか?」という質問に高速な1ステップで答えます。 見た値の set を保持し、結果用のリストも用意して、初めて遭遇した値のみを追加してください。
Write dedupe(xs) that returns a new list with duplicates removed, keeping the order of first appearance. · dedupe(xs) を書いて、重複を除去した新しいリストを返してください。最初の出現順の順序を保ちます。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。