WOLFRAM

SubsetCases[list,patt]

gives a list of the sublists in list that match the pattern patt in any order.

SubsetCases[list,pattrhs]

gives a list of the values of rhs corresponding to matching sublists.

SubsetCases[list,patt,n]

includes only the first n matches.

Details and Options

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Find sublists that match a pattern:

Out[1]=1

Perform a replacement on each match:

Out[2]=2

Scope  (3)Survey of the scope of standard use cases

Find subsets of variable length:

Out[1]=1

Combine a variable-length and a fixed-length pattern:

Out[2]=2

For a variable-length pattern, SubsetCases returns the longest match:

Out[1]=1

With OverlapsTrue, all possible matches are returned in order of decreasing length:

Out[2]=2

SubsetCases tries different branches of Alternatives (|) until one matches:

Out[1]=1

A different order of the pattern produces a different result:

Out[2]=2

Options  (1)Common values & functionality for each option

Overlaps  (1)

Allow overlaps:

Out[1]=1

Allow no overlaps:

Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Find triangles in a directed graph:

Out[3]=3

Highlight the triangles:

Out[4]=4

Find cycles of length four in an undirected graph:

Out[2]=2

Highlight the cycles:

Out[3]=3

Properties & Relations  (3)Properties of the function, and connections to other functions

The order of elements in each result is determined by the pattern:

Out[2]=2

Verify that each result matches the pattern:

Out[3]=3

Choose a different order of pattern and result:

Out[5]=5

Find all subset positions including overlaps:

Out[2]=2

Extract the subsets:

Out[3]=3

The result is equivalent to that of SubsetCases:

Out[4]=4
Out[5]=5

Find all subsets:

Out[1]=1

Find the same result using Subsets:

Out[2]=2
Out[3]=3
Wolfram Research (2020), SubsetCases, Wolfram Language function, https://reference.wolfram.com/language/ref/SubsetCases.html.
Wolfram Research (2020), SubsetCases, Wolfram Language function, https://reference.wolfram.com/language/ref/SubsetCases.html.

Text

Wolfram Research (2020), SubsetCases, Wolfram Language function, https://reference.wolfram.com/language/ref/SubsetCases.html.

Wolfram Research (2020), SubsetCases, Wolfram Language function, https://reference.wolfram.com/language/ref/SubsetCases.html.

CMS

Wolfram Language. 2020. "SubsetCases." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SubsetCases.html.

Wolfram Language. 2020. "SubsetCases." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SubsetCases.html.

APA

Wolfram Language. (2020). SubsetCases. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SubsetCases.html

Wolfram Language. (2020). SubsetCases. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SubsetCases.html

BibTeX

@misc{reference.wolfram_2025_subsetcases, author="Wolfram Research", title="{SubsetCases}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/SubsetCases.html}", note=[Accessed: 09-May-2025 ]}

@misc{reference.wolfram_2025_subsetcases, author="Wolfram Research", title="{SubsetCases}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/SubsetCases.html}", note=[Accessed: 09-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_subsetcases, organization={Wolfram Research}, title={SubsetCases}, year={2020}, url={https://reference.wolfram.com/language/ref/SubsetCases.html}, note=[Accessed: 09-May-2025 ]}

@online{reference.wolfram_2025_subsetcases, organization={Wolfram Research}, title={SubsetCases}, year={2020}, url={https://reference.wolfram.com/language/ref/SubsetCases.html}, note=[Accessed: 09-May-2025 ]}