title: Idiomatic way to return the element before an element that matches a function in a list
body: <p>Lets say I have this input:</p>
  
  <pre><code>d=['List', 'of', 'devices', 'attached', '33ddd323514d7', 
     'device', '8742323455', 'device']
  </code></pre>
  
  <p>and I want to return all list elements that occur directly before an occurrence of a list element whose value is equal to <code>'device'</code> [which in this case would be the elements which correspond to the values of '33ddd323514d7' and '8742323455']. What is the best way to do this? Right now I do this: </p>
  
  <pre><code>[i[0] for i in zip(d[:-1],d[1:]) if i[1]=="device"]
  </code></pre>
  
  <p>Is there an easier more idiomatic way (or a standard library function) to accomplish this type of thing?</p>