1
$\begingroup$

I don't know how to delete a list from a list.

For example, There is a list.

box[1, 1] = {{50, {5, 3}}, {3.6463, {5, 3}}, {50, {5, 3}}, {50, {5, 3}}, {50, {5, 3}}, {81.490, {5, 3}}, {50, {5, 3}}, {20.2414, {5, 3}}, {42.439, {5, 3}}, {50, {5, 3}}};

select = RandomSample[box[1, 1], Take[5]];

Next, I want to create new list like newbox[1,1] = box[1,1] - select.

For example, If select is

select={{50, {5, 3}}, {42.439, {5, 3}}, {81.490, {5, 3}}, {50, {5, 3}}, {50, {5, 3}}}

, newbox[1,1] should be

newbox[1,1]={{20.2414, {5, 3}},{50, {5, 3}}, {3.6463, {5, 3}},{50, {5, 3}},{50, {5, 3}}}

however, i couldn't make list, I don't understand how to use DeleteCases.for example, I tried

newbox[1, 1] = DeleteCases[box[1, 1], Alternatives @@ select]

but,Alternatives @@ select was incorrect because the same number(here is {50, {5, 3}}) of elements is recognised as one.

What equation should I construct?

$\endgroup$
3
  • $\begingroup$ I hope new list obtained by subtracting "select" from "box[1,1]". $\endgroup$
    – hare
    Commented Nov 3, 2023 at 7:06
  • $\begingroup$ They are not only selects, but also box[1,1] is actually a randomly generated list. I don't want specific values, but I want to avoid that elements with exactly the same value are not considered as one element and are selected in duplicate. $\endgroup$
    – hare
    Commented Nov 3, 2023 at 7:15
  • $\begingroup$ Yes,,,,,,,,,,,,,(, filling up of the minimum number of characters. $\endgroup$
    – hare
    Commented Nov 3, 2023 at 7:26

2 Answers 2

1
$\begingroup$

I am using a slightly modified list:

orig = {{50, {5, 3}}, {3.6463, {5, 3}}, {51, {5, 3}}, {50, {5, 
     3}}, {52, {5, 3}}, {81.490, {5, 3}}, {50, {5, 3}}, {20.2414, {5, 
     3}}, {42.439, {5, 3}}, {49, {5, 3}}};

select = {{50, {5, 3}}, {42.439, {5, 3}}, {81.490, {5, 3}}, {51, {5, 
    3}}, {50, {5, 3}}};

Using Complement: (which treats lists as sets)

Complement[orig, select]

{{3.6463, {5, 3}}, {20.2414, {5, 3}}, {49, {5, 3}}, {52, {5, 3}}}


Using DeleteCases:

DeleteCases[orig, _?(MemberQ[select, #] &)]

{{3.6463, {5, 3}}, {52, {5, 3}}, {20.2414, {5, 3}}, {49, {5, 3}}}

$\endgroup$
2
  • $\begingroup$ I am grateful for your assistance! $\endgroup$
    – hare
    Commented Nov 3, 2023 at 10:18
  • $\begingroup$ @hare, I am glad I was able to help. Thanks for the accept. $\endgroup$
    – Syed
    Commented Nov 3, 2023 at 10:21
1
$\begingroup$

You can use DeleteElements which came with V 13.1

It gives the desired result, but in a slightly different sort order.

 box =
  {{50, {5, 3}}, {3.6463, {5, 3}}, {50, {5, 3}}, {50, {5, 3}},
   {50, {5, 3}}, {81.490, {5, 3}}, {50, {5, 3}}, {20.2414, {5, 3}},
   {42.439, {5, 3}}, {50, {5, 3}}};

select =
 {{50, {5, 3}}, {42.439, {5, 3}}, {81.490, {5, 3}}, {50, {5, 3}}, {50, {5, 3}}};

newbox = DeleteElements[box, 1 -> select]

{{3.6463, {5, 3}}, {50, {5, 3}}, {50, {5, 3}}, {20.2414, {5, 3}}, {50, {5, 3}}}

$\endgroup$
1
  • $\begingroup$ Thank you for your help! $\endgroup$
    – hare
    Commented Nov 3, 2023 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.