# How Pick function work when data is not a list?

This is from the Document center.

In[548]:= Pick[f[1, 2, 3, 4, 5, 6], {1, 0, 1, 0, 1, 1}, 1]

Out[548]= f[1, 3, 5, 6]


Can anyone explain how this work when data is not a list?

Pick[list,sel,patt]
picks out those elements of list for which the corresponding element of sel matches patt.

How do they determine corresponding element when they aren't the same type? Also not even a list?

sel = {1, Cos[1], Sin[1]};
list = {a, b, f[b]};
Pick[list, sel, 1]


Why is the output {a, f[b]} not {a, b}because only 1 in Sin[1] matches the pattern instead?

• I read that already but still not clear how do they determine corresponding element? Commented Dec 29, 2020 at 12:52

The documentation page says "The heads in list and sel do not have to be List."

Any heads will work, e.g. Pick[f[1, 2, 3, 4, 5, 6], x[1, 0, 1, 0, 1, 1], 1] (unless f or x evaluate to something incompatible).

The first, third, fifth and sixth elements of sel (or x) are 1s, as specified by patt, so those are the elements of f picked.

sel = {1, Cos[1], Sin[1]};
list = {a, b, f[b]};
Pick[list, sel, 1]

{a, f[b]}


The documentation says for this case (in Properties & Relations): The comparison in Pick[list, sel, patt ] is purely structural, with no regard to heads.

An argument in sel containing 1 is matched to the argument in list.

Pick[{f[a], b, f[b, c]}, {Sin[0], Cos[1], x[0, 1]}, 1]

{f[c]}

• Do they rely on level to determine corresponding element? How about this case? sel = {1, Cos[1], Sin[1]}; list = {a, b, f[b]}; Pick[list, sel, 1] why the output is {a, f[b]} not {a, b}? Commented Dec 29, 2020 at 14:40