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)能一步快速回答「我见过这个吗?」。用一个 set 记录见过的值,用一个列表存放结果,只在第一次遇到某个值时把它加入结果。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩