Linked Questions

11 votes
5 answers
7k views

How to subtract one list from another, treating each elements as distinct, assuming the smaller list is a subset of the larger list? [duplicate]

Suppose that I have two lists of different sizes, the smaller of which is a subset of the larger, e.g. a = {"A", "A", "A", "B", "B", "C"} b = {"A", "B"} How can ...
Taiki's user avatar
  • 5,239
5 votes
4 answers
298 views

Efficient way to compute a complement while respecting multiplicities [duplicate]

Suppose I have list2 which is a subset of list1. I want to get a res by deleting an element ...
vapor's user avatar
  • 7,901
2 votes
3 answers
574 views

How to do subtraction with sets in which the elements have multiplicity indicators? [duplicate]

I want to do subtraction with sets l1 and l2, which contain multiplicity indicators. For example, ...
Eden Harder's user avatar
  • 1,145
2 votes
3 answers
389 views

Deleting one of each chosen elements in a list containing duplicates [duplicate]

I want to delete one of each (and not all) selected element in a list containing duplicates. For example i have the list: $\{1,1,1,2,2,3\}$ and i want to delete $\{1,3\}$ so the leftover should be $\{...
kon's user avatar
  • 263
1 vote
1 answer
317 views

What is the fastest way to delete multiple entries from a list? [duplicate]

Mathematica allows Deleting multiple objects from a list given their position. However, if I don't know their positions (finding their positions in the list is too costly if the list is long), how can ...
Iconoclast's user avatar
1 vote
0 answers
132 views

Removing every member of a list from another list [duplicate]

I have a list of lists A={{1,2},{3,6},{7,8},{5,0}}, and another list of lists B={{1,2},{5,0}}. If any list in B is also in A, I want to remove them from A. E.g.,Taking {1,2} and {5,0} out of A to get ...
I A's user avatar
  • 23
602 votes
19 answers
156k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
48 votes
10 answers
17k views

How to delete elements from list1 appearing in list2?

I'm new to functional programming of Mathematica and trying to remove one list of assorted elements from another. However I only find functions working with the Index rather than the values itself: ...
PeriodicProgrammer's user avatar
22 votes
10 answers
2k views

How do I delete all items that occur more than once?

DeleteDuplicates works fine but leaves a single copy of the duplicated item. I need to remove all items that occur more than once i.e. {{1,2},{1,2},{3,4}} -> ...
Boris's user avatar
  • 421
17 votes
9 answers
773 views

DeleteCases for once only

I want to delete an array of elements from another one, DeleteCases seems to be an option, but the problem is that it deletes an element more than once if available,...
user49535's user avatar
  • 1,185
14 votes
8 answers
2k views

Given an ordered set S, find the points in S corresponding to another list

Given a sorted list of numbers $S$, I want to create a function that accepts a list of numbers $L$ and for each number $l \in L$ it returns the index of the largest number $s \in S$ such that $s<l$....
Carl Woll's user avatar
  • 130k
14 votes
9 answers
2k views

Filtering elements from a list that appear only once

I want to be able to select elements from a list that only appear once. I originally had this: Select[Table[Count[list, i], {i, list}], # == 1] But the issue is ...
Mark's user avatar
  • 201
13 votes
6 answers
934 views

Efficiently finding the positions of a large list of targets in another, even larger list

I have a big list. It contains nearly 60,000 sub-lists. It's structured like bigList = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},.....,{x60000,y60000,z60000}}; I have ...
subbu's user avatar
  • 2,304
12 votes
5 answers
823 views

Complement of multisets

Given lists $a$ and $b$, which represent multisets, how can I compute the complement $a\setminus b$? I'd like to construct a function xunion that returns the ...
Leo's user avatar
  • 1,155
14 votes
5 answers
2k views

Find all the possible ways of partitioning a list into a set of pairs of element

I have a list {x1,...,xN} where N is even, and I need to find all the possible ways to split it into pairs of elements, e.g. the ...
sdnnds's user avatar
  • 383

15 30 50 per page