Skip to content

Pick ​

Elements of list whose corresponding element of sel matches patt (default True).

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguagePick✓
Pick(list, sel)elements of list where the corresponding sel element is True
Pick(list, sel, patt)elements of list where the corresponding sel element matches patt
Typed signatures
TypePackageApplies
(list<any>, list<any>, any?) -> list<any>combinatoricsalways

Domain: Collections

Details
  • list and sel must be the same length.
  • Matching uses the same wildcard grammar as MatchQ.

Examples

Basic #
live ↗
InPick([a,b,c],[True,False,True])\mathrm{Pick}(\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack\mathrm{True}, \mathrm{False}, \mathrm{True}\bigr\rbrack)Out[a,c]\bigl\lbrack a, c\bigr\rbrack
live ↗
InPick([a,b,c,d,k],[1,0,1,0,0],1)\mathrm{Pick}(\bigl\lbrack a, b, c, d, k\bigr\rbrack, \bigl\lbrack1, 0, 1, 0, 0\bigr\rbrack, 1)Out[a,c]\bigl\lbrack a, c\bigr\rbrack
live ↗
InPick([[a,b,c],[d,k,f]],[[1,0,0],[0,1,1]],1)\mathrm{Pick}(\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack d, k, f\bigr\rbrack\bigr\rbrack, \bigl\lbrack\bigl\lbrack1, 0, 0\bigr\rbrack, \bigl\lbrack0, 1, 1\bigr\rbrack\bigr\rbrack, 1)Out[[a],[k,f]]\bigl\lbrack\bigl\lbrack a\bigr\rbrack, \bigl\lbrack k, f\bigr\rbrack\bigr\rbrack
Scope #
live ↗
InPick([a,b,c,d],[1,0,1,0],1)\mathrm{Pick}(\bigl\lbrack a, b, c, d\bigr\rbrack, \bigl\lbrack1, 0, 1, 0\bigr\rbrack, 1)Out[a,c]\bigl\lbrack a, c\bigr\rbrack

A Boolean mask selects the corresponding elements

live ↗
InPick([a,b,c,d],[True,False,False,True])\mathrm{Pick}(\bigl\lbrack a, b, c, d\bigr\rbrack, \bigl\lbrack\mathrm{True}, \mathrm{False}, \mathrm{False}, \mathrm{True}\bigr\rbrack)Out[a,d]\bigl\lbrack a, d\bigr\rbrack
About
Examples5
Checked againstWolfram Language 5 agree
CrosswalkWolfram Language

See also: Level, MatchQ