title: Python - Is there a way to add an "as" alias to a for loop?
body: <p>Note: <code>python --version</code> yields <code>Python 3.6.4 :: Anaconda, Inc.</code></p>
  
  <p>I'm working with some <code>itertools</code> code that seems pretty intent on putting out tuples, but I want to loop over each result as a <code>numpy.array</code>. Use case: Have a data set with ~10 features and I'm curious about brute-forcing all feature set combinations for a clustering fit.</p>
  
  <p>So I tried this: </p>
  
  <pre><code>from itertools import chain, combinations
  import numpy as np
  def the_python_way(value_list):
      # creates a generator on an iterator; not sure which
      def powerset(iterable):
          # Note: Seems to forcefully make the results tuples. Casting the tuple 
          # produced by combinations(...) to something else seems to alter the 
          # production order a bit, but when I check the type produced by the 
          # final chain.from_iterable(...) it still says "tuple". Weird.
          return chain.from_iterable(
                  np.array(combinations(iterable, len_n))
                  for len_n in range(len(iterable)+1))
  
      for item in powerset(value_list):
          print("type: ", type(item), ", item: ", np.array(item))
  
  the_python_way([1,2,3])
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>type:  &lt;class 'tuple'&gt; , item:  ()
  type:  &lt;class 'tuple'&gt; , item:  (1,)
  type:  &lt;class 'tuple'&gt; , item:  (2,)
  type:  &lt;class 'tuple'&gt; , item:  (3,)
  type:  &lt;class 'tuple'&gt; , item:  (1, 2)
  type:  &lt;class 'tuple'&gt; , item:  (1, 3)
  type:  &lt;class 'tuple'&gt; , item:  (2, 3)
  type:  &lt;class 'tuple'&gt; , item:  (1, 2, 3)
  </code></pre>
  
  <p>Huh. I could just override the loop value:</p>
  
  <pre><code># attempt 1: just cast to np.array(item)
  for item in powerset(value_list):
      item = np.array(item)
      # carry on
  </code></pre>
  
  <p>But that seems a little too C. Here's what I'd like to do:</p>
  
  <pre><code># attempt 2: syntax error
  for np.array(value) as item in powerset(value_list):
      # carry on
  </code></pre>
  
  <p>Not as preferable, but I'd hoped this might work. Nope:</p>
  
  <pre><code># attempt 5: syntax error
  for np.array(value) in powerset(value_list) as item:
      # carry on
  </code></pre>
  
  <p><strong>Is there a way to 'as' in a for loop?</strong></p>
  
  <p>My google searches haven't turned up any questions about this on stackoverflow, but I'd be surprised if I was the first person to actually ask. Maybe I didn't search with the right keywords.</p>
  
  <p>I've read <a href="https://www.w3schools.com/python/ref_keyword_as.asp" rel="nofollow noreferrer">this w3schools entry on 'as'</a>, but it doesn't say anything about use in a for loop. If it isn't on w3schools, I'm guessing that this isn't a thing that Python can do, but I wanted to check stackoverflow anyway.</p>