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 משיב "האם ראיתי זאת כבר?" בשלב מהיר אחד. שמור 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. · לחץ על הרץ כדי לראות את התוצא כאן.