Count() Method Of Deque Class

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:

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:

Number of ones in the sequence

3

Number of fives in the sequence

2

 


Copyright 2023 © pythontic.com