How to get rid of duplicates in a list, but keep the order

前端 未结 8 1280
情话喂你
情话喂你 2021-02-15 15:13

I am using Intermediate Student with Lambda in DrRacket, I was wondering how one would remove the duplicates in a list, while keeping the order. For example (remo

8条回答
  •  暖寄归人
    2021-02-15 16:15

    I'm not sure if this is homework, but in case it is I'll post just the idea. If it's not tell me and I can put a solution here.

    What you need is to keep track of the unique items you find, you can do that by using an auxiliary list, like an accumulator, to keep track of the ones you found so far.

    Whenever you look at another item check to see if it's in the auxiliary list. In case it's not add it to the auxiliary list.

    You'll end up with a reverse order of what you're trying to find, so you can just (reverse ...) it and you'll have your answer.

提交回复
热议问题