title: Python - Iterating through a deque with popleft()
body: <p>I've been looking for the best way to iterate through a deque while using popleft to use the first element and reduce the queue for each iteration. I essentially want to popleft the first in the deque, run some code using this value and then do the same process until there are no more values left in the deque.</p>
  
  <p>The best I've found online is using a try and catch block to capture an IndexError:</p>
  
  <pre><code>try: 
      while mydeque: 
          value = mydeque.popleft()
  except IndexError: 
  # handle empty mydeque
  </code></pre>
  
  <p>Surely throwing an exception isn't the best way to do this. I'd be catching any IndexError occurring in the while loop as well, which isn't ideal. Using a for loop doesn't work as I'd be modifying the deque during the iteration.</p>
  
  <p>What's the best way to do this?</p>