# From the list of 3-tuples, how can I select tuples which contain one for more nines? [closed]

From the list

Tuples[{1, 2, 3, 4, 9}, 3]


how can I select exactly those 3-tuples that contain one for more nines?

This is the result I want:

{{1, 1, 9}, {1, 2, 9}, {1, 3, 9}, {1, 4, 9}, {1, 9, 1}  ... {9, 9, 4}, {9, 9, 9}}

• Help > Wolfram Docuentation, enter "select" (with or without quotes). First hit is to Select... – Daniel Lichtblau Jun 2 at 11:59

list=Tuples[{1, 2, 3, 4, 9}, 3] ;
Cases[{___,9,___}]@list


{{1, 1, 9}, {1, 2, 9}, {1, 3, 9}, {1, 4, 9}, {1, 9, 1}, {1, 9, 2}, {1, 9, 3}, {1, 9, 4}, {1, 9, 9},
{2, 1, 9}, {2, 2, 9}, {2, 3, 9}, {2, 4, 9}, {2, 9, 1}, {2, 9, 2}, {2, 9, 3}, {2, 9, 4}, {2, 9, 9},
{3, 1, 9}, {3, 2, 9}, {3, 3, 9}, {3, 4, 9}, {3, 9, 1}, {3, 9, 2}, {3, 9, 3}, {3, 9, 4}, {3, 9, 9},
{4, 1, 9}, {4, 2, 9}, {4, 3, 9}, {4, 4, 9}, {4, 9, 1}, {4, 9, 2}, {4, 9, 3}, {4, 9, 4}, {4, 9, 9},
{9, 1, 1}, {9, 1, 2}, {9, 1, 3}, {9, 1, 4}, {9, 1, 9}, {9, 2, 1}, {9, 2, 2}, {9, 2, 3}, {9, 2, 4}, {9, 2, 9},
{9, 3, 1}, {9, 3, 2}, {9, 3, 3}, {9, 3, 4}, {9, 3, 9}, {9, 4, 1}, {9, 4, 2}, {9, 4, 3}, {9, 4, 4}, {9, 4, 9},
{9, 9, 1}, {9, 9, 2}, {9, 9, 3}, {9, 9, 4}, {9, 9, 9}}

try

Select[Tuples[{1,2,3,4,9},3],MemberQ@9]


{{1,1,9},{1,2,9},{1,3,9},{1,4,9},{1,9,1},{1,9,2},{1,9,3},{1,9,4},{1,9,9},{2,1,9},{2,2,9},{2,3,9},{2,4,9},{2,9,1},{2,9,2},{2,9,3},{2,9,4},{2,9,9},{3,1,9},{3,2,9},{3,3,9},{3,4,9},{3,9,1},{3,9,2},{3,9,3},{3,9,4},{3,9,9},{4,1,9},{4,2,9},{4,3,9},{4,4,9},{4,9,1},{4,9,2},{4,9,3},{4,9,4},{4,9,9},{9,1,1},{9,1,2},{9,1,3},{9,1,4},{9,1,9},{9,2,1},{9,2,2},{9,2,3},{9,2,4},{9,2,9},{9,3,1},{9,3,2},{9,3,3},{9,3,4},{9,3,9},{9,4,1},{9,4,2},{9,4,3},{9,4,4},{9,4,9},{9,9,1},{9,9,2},{9,9,3},{9,9,4},{9,9,9}}

• This can even be shortened to Select[Tuples[{1,2,3,4,9},3], MemberQ[9]]. – Henrik Schumacher Jun 2 at 9:36
• @HenrikSchumacher nice! – J42161217 Jun 2 at 9:58
L = Tuples[{1, 2, 3, 4, 9}, 3];

Pick[L, Total /@ UnitBox[L - 9], 1 | 2 | 3]


Or

Pick[L, Total /@ UnitStep[L - 8], 1 | 2 | 3]

lst // Pick[#, Times@@@(# /. 9-> 0), 0] &


and

Pick[lst,Times@@@(lst/. 9-> 0),0]==
Pick[lst, MemberQ[#,9]&/@lst]