Skip to content · ⁨コンテンツへスキップ⁩

Remove duplicates · ⁨重複を削除⁩

English

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 を保持し、結果用のリストも用意して、初めて遭遇した値のみを追加してください。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP