Python: Get the number of occurrences of a specified element in an array
Python: Array Exercise-6 with Solution
Write a Python program to get the number of occurrences of a specified element in an array.
Python Code :
from array import * array_num = array('i', [1, 3, 5, 3, 7, 9, 3]) print("Original array: "+str(array_num)) print("Number of occurrences of the number 3 in the said array: "+str(array_num.count(3)))
Original array: array('i', [1, 3, 5, 3, 7, 9, 3]) Number of occurrences of the number 3 in the said array: 3
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to get the current memory address and the length in elements of the buffer used to hold an array’s contents and also find the size of the memory buffer in bytes.
Next: Write a Python program to append items from inerrable to the end of the array.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Python: Unpack a Tuple
>>> items = (0, 'b', 'one', 10, 11, 'zero') >>> a, b, c, d, e, f = items >>> print(f) zero >>> a, *b, c = items >>> print(b) ['b', 'one', 10, 11] >>> *_, a, b = items >>> print(a) 11
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework