# How to efficiently count occurrence of some element in a list? [closed]

I have a list of numbers, for example:

list = {1,2,3,4,2,1,3};


what would be efficient way to count all occurrences of some number? I tried so far:

Length[Select[list, # > 0 &]]


But I am sure it can be done somehow more efficient.

-
Look up Count on documentation. –  Spawn1701D Jun 13 at 21:28
@Spawn1701D Count[{1, 2, 3}, # == 1 &] does not work at all or I don't know how to put criteria into a pattern. –  Herudaio Jun 13 at 21:47
Count[{1,2,3},1] will do the job. –  mmal Jun 13 at 21:50
@Herudaio What you have there is a test function, not a pattern. To make it a pattern use PatternTest (?) like this: _?(# == 1 &). Look at Select and Cases to see two very similar functions that use test functions and patterns, respectively. –  Sjoerd C. de Vries Jun 13 at 21:56
A few of the structure functions take patterns rather than functions. Pattern vs function feels redundant at first, but it's necessary/useful overall. –  amr Jun 13 at 22:52