Remove() Method Of Deque Class In Python Collections Module

Method Name:

remove

 

Method Signature:

remove(value)

 

Method Overview:

  • remove() method removes the first occurrence of the value from the deque as specified the value parameter.

 

  • If the deque object does not have any element with the specified value, remove() raises an exception of type ValueError.

 

Example:

import collections

 

tokens          = ("I", "chatter", "chatter", "as", "I", "flow")

poetryDeque     = collections.deque(tokens)

removeValue     = "chatter"

 

print("Deque entries before remove():")

print(poetryDeque)

 

poetryDeque.remove(removeValue)

 

print("Deque entries after removing the entry:%s"%(removeValue))

print(poetryDeque)

 

Output:

Deque entries before remove():

deque(['I', 'chatter', 'chatter', 'as', 'I', 'flow'])

Deque entries after removing the entry:chatter

deque(['I', 'chatter', 'as', 'I', 'flow'])


Copyright 2023 © pythontic.com