title: How to get list index and element simultaneously in Python?
body: <p>I find myself frequently writing code like this:</p>
  
  <pre><code>k = 0
  for i in mylist:
      # y[k] = some function of i
      k += 1
  </code></pre>
  
  <p>Instead, I could do</p>
  
  <pre><code>for k in range(K):
      # y[k] = some function of mylist[k]
  </code></pre>
  
  <p>but that doesn't seem "pythonic". (You know... indexing. Ick!) Is there some syntax that allows me to extract both the index (k) and the element (i) simultaneously using either a loop, list comprehension, or generator? The task is in scientific computing, so there is a lot of stuff in the loop body, making a list comprehension probably not powerful enough on its own, I think.</p>
  
  <p>I welcome tips on related concepts, too, that I might not have even though of. Thank you.</p>