1
$\begingroup$

I have been trying to remove duplicates elements from a list using delete cases instead of the conventional deleteDuplicates function. I wrote something like

DeleteCases[list,x_ y_/;(x-y)==0] which obviously did not work. How do I iterate over different elements in the list without using for loops or while ?

$\endgroup$
  • 1
    $\begingroup$ Are you sure you don't want DeleteDuplicates? You can supply a second argument, i.e., DeleteDuplicates[list,#-#2==0.&] $\endgroup$ – b3m2a1 Mar 14 '17 at 6:21
  • 1
    $\begingroup$ Why not use Union? $\endgroup$ – Anjan Kumar Mar 14 '17 at 6:21
  • 1
    $\begingroup$ @AnjanKumar Union will apply a sorting to the list. That's unnecessary if he just wants to remove the duplicates. There DeleteDuplicates is sufficient. $\endgroup$ – b3m2a1 Mar 14 '17 at 6:23
  • $\begingroup$ @AbheshekPal asked about removing the same elements without using cycles. And he wrote about deleteDublicates. I thought it is not appropriate for the your task $\endgroup$ – Kirill Belov Mar 14 '17 at 7:51

Browse other questions tagged or ask your own question.