The count() method of deque class

The count method of deque class counts the number of times an element is present in a python deque instance and returns the count value.

Deque Updated 18 Mar 2017 1 min read

Method Name

count()

Method Signature

count(element)

Method overview

  • The method count() returns the number of times a specific element appears in a deque object.

Example

python
import collections

# A tuple of random sequence

randomSequence = (1,2,3,4,5,5,1,2,6,1)

# Create a deque out of a tuple

deckInstance = collections.deque(randomSequence)

# Count number of ones in the sequence

print("Number of ones in the sequence")

print(deckInstance.count(1))

# Count number of fives in the sequence

print("Number of fives in the sequence")

print(deckInstance.count(5))

Output

Output
Number of ones in the sequence

3

Number of fives in the sequence

2