Removing Duplicates in a List

I really have trouble just trying to create code that only removes the duplicates and keeps the original on a list of names(please just keep it simple so that I can understand?)

There's a procedure on [scratchblocks][length v] of (list [a][b]@delInput@addInput ::list) :: list[/scratchblocks] named uniques. You can put your list there and switch it to uniques.

Is it important whether e.g. the first or the last of multiple entries is kept?
And is it an exercise you’re supposed to learn from?
(@tethrarxitet ’s is the quick fix)

this shouldnt be in Snap! Bugs .

here is your answer tho.
untitled script pic (1)

  1. I don't really know where to put this as i already have and existing code for this and

  2. i don't really know how to "add" or post my code to show you what i mean, so sorry..

go into your projects. click on your project but while on the project dont click edit. then click publish. copy the link and share it.

thank you.

send the link here and tell me what you want to do with the project.

https://snap.berkeley.edu/snap/snap.html#present:Username=jabbadaconqerer&ProjectName=Book%20recomendation

Now what i wanted to do was edit a specific piece of code that i edited from a previous project that would delete all duplicates in a list.Now the problem is i want to delete the multiple items and keep one item(it's hard to explain)

I want it to be like the Uniques procedure, except it works on a existing list.

I think Requests to the Community would be fitting for this post.

Or Snap! Editor

As a general rule, editing a list while traversing it is rather tricky. You’d better use a functional approach, building a new list, like in this example:

did you do it

If you mean: “did you write it yourself?”: the answer is yes, and I wrote it on the fly. The code is written in a functional style, and utilizes recursion. Though many people find it difficult to write this kind of code, I find it very easy. Mastering recursion is like learning to ride a bike: at first you feel you’re never going to ride 10 meters (or yards) without falling, while once you get tne hang of it, it’s the most natural thing to do.
But perhaps that wasn’t what you were asking…

that wasnt my question. did he fix it

I dont really want to create new code and i really don't care about how hard it is to edit a list while traversing it all i care about if it it works And if i can understand it enough to explain it to other people if need be.

Your idea is nice and all, but i don't think i can implement it into my code.

Is this what you’ve been looking for?

I’m not sure what you’re looking for, because your original code is a command but its definition script has report as its final block, and the label of your original block says “leave original”.

So alternatively, you could simply use:

Now using uniques of … has two downsides: (1) the order of the items is shuffled a bit; (2) it is not obvious how it works. So if this is for an assignment, and you’re supposed to show you understand how duplicates are removed from the list, you could use my earlier example code (or make your own variation):

Or, if you insist on improving your imperative-style code:

What I changed:

  1. Traversing the list from the length of the list down to 1 instead of the other way around. Now your code isn’t going to be troubled by list items that were removed in the process;
  2. You don’t need “j” if you have “i” start at length - 1;
  3. Replaced delete (item (k) of (list)) from (list) with delete (k) of (list);
  4. Took out the report block, which doesn’t do anything in a command script.

BTW this block doesn't work for empty or singleton lists. You could add a test for that.

well, thank you! I will try to work on the empty list problem, and the Singleton List problem?(I need some explanation to what that is.)Overall thank you.