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?
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?
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
Although most of the time you'd want to use the in
operator for membership testing, which deque
s support, you also have the option of using its count()
method — which actually provides more information and so might be more useful depending on exactly what you're trying to accomplish.
>>> import collections
>>> d = collections.deque([0, 3, 5, 1, 5, 8])
>>> d.count(5)
2
>>> d.count(20)
0
>>> bool(d.count(5))
True
>>> bool(d.count(20))
False