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
- In SubsetCases[list,patt], patt can be an expression with head List that includes pattern constructs such as PatternSequence, Repeated (..), Blank (_) and BlankSequence (__).
- The pattern patt can also be a pattern that matches a list but does not itself have head List.
- With the default option setting OverlapsFalse, SubsetCases includes only sublists that do not overlap. With the setting OverlapsTrue, it includes sublists that overlap.
Examples
open allclose allScope (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:
Applications (2)
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:
The result is equivalent to that of SubsetCases:
Find the same result using Subsets:
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