# How to remove elements from a list that are less than a certain number? [closed]

If I have a list like:

list = {23,21,18,15,13,12,10,9,8,7,7,5}


How can I remove numbers from that list so that no number less than 13 is on it without hardcoding, so if the list were different it would still remove any numbers less than 13?

I tried using the position like:

position = Position[list, 2]
listNew = list[[1;;position]]


It doesn't work because position's output is

{{10}}


## closed as off-topic by Bob Hanlon, MarcoB, ilian, m_goldberg, dr.blochwaveNov 19 '15 at 23:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, MarcoB, ilian, m_goldberg, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

• closely related 180 – Kuba Nov 19 '15 at 17:57
• A built-in function to remove elements from a list would be DeleteCases. This should evaluate to what you are looking for: DeleteCases[list,_?(# < 13 &)]. – user31159 Nov 19 '15 at 18:23
• What about marking this as a duplicate of 24167 – Kuba Nov 19 '15 at 18:32

list = {23, 21, 18, 15, 13, 12, 10, 9, 8, 7, 7, 5};
Select[list, # >= 13 &]


{23, 21, 18, 15, 13}

Pick[list, UnitStep[list - 13], 1]


$\${23, 21, 18, 15, 13}

If you want to use Position

pos = Flatten @ Position[list, _?(# >= 13 &)]


{1, 2, 3, 4, 5}

list[[pos]]


{23, 21, 18, 15, 13}

Since your list is ordered it's more efficient to write

pos = First@FirstPosition[list, _?(# <= 13 &)]


5

list[[;; pos]]


{23, 21, 18, 15, 13}

• ...but if you like patterns so much, then use Cases[] instead. ;) – J. M. will be back soon Nov 19 '15 at 17:52

Replacement rules are another option - just for exposure to new ideas. This will be slow on big lists.

list = {23,21,18,15,13,12,10,9,8,7,7,5}
newList = list/. _?(# < 13 &)->Sequence[]


gives {23, 21, 18, 15, 13}

• Since 10.2 one can use Nothing instead of Sequence[]. – gwr Nov 19 '15 at 19:24