fork download
  1. # Python program to count
  2. # occurrences of an
  3. # element in an unsorted
  4. # array
  5. def frequency(a, x):
  6. count = 0
  7.  
  8. for i in a:
  9. if i == x: count += 1
  10. return count
  11.  
  12. # Driver program
  13. a = [0, 5, 5, 5, 4]
  14. x = 5
  15. print(frequency(a, x))
  16.  
  17. # This code is contributed by Ansu Kumari
Success #stdin #stdout 0.08s 14196KB
stdin
Standard input is empty
stdout
3