title: Extract list element in Python
body: <p>This is my first python program. I use the below code to generate combinations for a given range. </p>
  
  <pre><code>for k in range(0, items+1):        
      for r in range(0, items+1):        
          if (r-k) &gt; 0:
              res = [x for x in itertools.combinations(range(k, r), r-k)]            
              print res
  </code></pre>
  
  <p>Let say items=4, the code produce 10 combinations</p>
  
  <pre><code>            #     
              # [(0,)]
              # [(0, 1)]
              # [(0, 1, 2)]
              # [(0, 1, 2, 3)]
              # [(1,)]
              # [(1, 2)]
              # [(1, 2, 3)]
              # [(2,)]
              # [(2, 3)]
              # [(3,)]
              #
  </code></pre>
  
  <p>My questions are</p>
  
  <ul>
  <li><p>(a) How can I retrieve each element in each combinations, let say, in  [(1, 2, 3)], how can I retrieve value at offset 0  (i.e. 1) ? </p></li>
  <li><p>(b) How can I store return value from itertools.combinations into a list array in "res" (eg, res[0] = [(0,)]  , res[1] = [(0, 1)] ?</p></li>
  <li><p>(c) Let say I want to use map(), How can I make the value eg [(0, 1)]  as key, and assign a random value to this key?</p></li>
  </ul>