Basic Examples (5)
Separate elements that are even:
Use a pure function to test each element:
Select only the first expression that satisfies the condition:
Use the operator form of SelectDiscard:
SelectDiscard operates on values in an Association:
Scope (6)
SelectDiscard gives elements for which applying the criterion explicitly yields True in the first list and everything else in the second:
Applying the criterion to the symbolic object x does not explicitly yield True:
Find pairs containing x:
Find up to 2 pairs containing x:
Fewer than the requested elements may be returned:
Use an operator form as the selection criterion:
Use SelectDiscard in operator form:
Separate arguments in Unevaluated code:
Generalizations & Extensions (4)
SelectDiscard works with any head, not just List:
SelectDiscard works with SparseArray objects:
The result includes a list since only one can be sparse:
Compare to Select:
Separate a Dataset:
Separate a Graph by testing its vertices:
Applications (5)
Select numbers up to 100 that equal 1 modulo both 3 and 5:
Select 4-tuples that read the same in reverse:
Select eigenvalues that lie within the unit circle:
Separate built-in Wolfram Language symbols based on whether their names contain less than 10 characters:
Select numeric quantities from a product:
Properties & Relations (7)
The lengths of list1 and list2 will always sum to the length of the original list:
When specifying a maximum, the second list can contain elements that satisfy the given condition:
SelectDiscard is similar to TakeDrop except it takes/drops elements using the given function:
For crit that always return True or False, SelectDiscard is very similar to GatherBy:
However, the first list returned by SelectDiscard always corresponds to elements ei where crit[ei] gives True:
Similar results can be obtained with GroupBy:
However, SelectDiscard works on expressions with any head:
GroupBy does not:
SelectDiscard always gives two lists:
Compare with GatherBy and GroupBy:
Similar results can be obtained with a combination of Select and DeleteElements:
SelectDiscard tends to perform better with large lists:
The first list returned by SelectDiscard[list,crit] is equivalent to what's returned by Select[list,crit]:
The second list is effectively equivalent to Select[list,Not@*TrueQ@*crit]:
Possible Issues (1)
When specifying a limit, the second list can contain elements ei where crit[ei] is True: