SubsetCases

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)

Find sublists that match a pattern:

Perform a replacement on each match:

Scope  (3)

Find subsets of variable length:

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

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

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

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

A different order of the pattern produces a different result:

Options  (1)

Overlaps  (1)

Allow overlaps:

Allow no overlaps:

Applications  (2)

Find triangles in a directed graph:

Highlight the triangles:

Find cycles of length four in an undirected graph:

Highlight the cycles:

Properties & Relations  (3)

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

Verify that each result matches the pattern:

Choose a different order of pattern and result:

Find all subset positions including overlaps:

Extract the subsets:

The result is equivalent to that of SubsetCases:

Find all subsets:

Find the same result using Subsets:

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.

CMS

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2023_subsetcases, organization={Wolfram Research}, title={SubsetCases}, year={2020}, url={https://reference.wolfram.com/language/ref/SubsetCases.html}, note=[Accessed: 16-April-2024 ]}