title: Double list comprehension in Python - finding borders coordinates
body: <p>Given <code>(x,y)</code>, I want the collection:</p>
  
  <pre><code>[(0,0),(0,y),(1,0),(1,y),(2,0),(2,y)...(x-1,0),(x-1,y),(x,0),(x,y),
               (0,1),(x,1),(0,2),(x,2)...(0,y-1),(x,y-1)]
  </code></pre>
  
  <p>(I don't really care if it is a list, set, or any other type of collection.)</p>
  
  <p>I've experimented with several permutations of list comps, nothing has really worked.</p>
  
  <p>I found a BAD solution::</p>
  
  <pre><code>all_points = list(itertools.product([x for x in range(x+1)], [y for y in range(y+1)]))
  border = [xy for xy in all_points if xy[0]==0 or xy[0]==x or xy[1]==0 or xy[1]==y]
  </code></pre>
  
  <p>But I really hate this solution and am wondering if there is a more direct approach. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The BAD solution can be made better, as mentioned below in comments:</p>
  
  <pre><code>all_points = list(itertools.product(range(x+1), range(y+1))
  border = [xy for xy in all_points if xy[0]==0 or xy[0]==x or xy[1]==0 or xy[1]==y]
  </code></pre>
  
  <p>But the problem remains --- i'm just getting all the coords and then dropping the ones that aren't in the comp...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The BAD solution can be made better still...</p>
  
  <pre><code>border = [xy for xy in itertools.product(range(x+1), range(y+1)) if xy[0]==0 or xy[0]==x or xy[1]==0 or xy[1]==y]
  </code></pre>
  
  <p>But I don't know how I feel about this...</p>
  
  <p><strong>EDIT -- what I really want to know is...</strong></p>
  
  <p>Is there a way to do some kind of (I dunno) recursive or loopy list comprehension that returns the desired results by directly building the list?</p>
  
  <p>I can solve the practical problem of finding the coords with the bad solution. But I want to grok list comps better.</p>