Search code examples
pythonqueuedeque

How do I find out if a value is in a deque?


say i have a deque with values [0,3,5,1,5,8]. I want to save all information about the deque including order, but I have to find if the value 5 is in the deque.

What is some pseudo-code that could determine this?


Solution

  • Are you aware of the in operator?

    >>> import collections
    >>> d = collections.deque([0,3,5,1,5,8])
    >>> 5 in d
    True
    >>> 20 in d
    False