title: Python - for loop of a list of ordered pairs and finding the greatest pair
body: <p>I have looked thoroughly, but have not found a clear (or roundabout) answer to the following question: How can I create a for loop that will allow me to find the greatest pair where x and y in (x,y) are greater than or equal to all other x's and y's in the list?</p>
  
  <p>So, suppose I have a list of 20 pseudorandom integer ordered pairs and I want to find which ordered pair is the greatest using a for loop.</p>
  
  <p>The code I currently have is:</p>
  
  <pre><code>np.random.seed(1234)
  a = np.random.randint(0, 11,(20,2))
  alst = list(allocationsset)
  print alst
  </code></pre>
  
  <p>Where np is the imported form of numpy and which prints,
  [[1,0],[8,9],[2,1],[3,2],[10,10] etc...]</p>
  
  <p>Then, I attempt to make the for loop with the following function:</p>
  
  <pre><code>def dominantx (pairs):
      def maxx (pairs):
          maxlist = []
          for [a,b] in pairs:
              if a &gt;= b:
                  maxlist.append([a,b])
          return maxlist
  
      dom = maxx(pairs)
      domlist = []
  
      for [a,b] in dom:
          for [c,d] in dom:
              if a &gt; c:
                  domlist.append([a,b])
              if a == c:
                  if b &gt; d:
                      domlist.append([a,b])
                  if b == d:
                      domlist.append([a,b])
                      domlist.append([c,d])
                  else:
                      domlist.append([c,d])
              else:
                  domlist.append([c,d])
      return domlist
  
  dominantx(alst)
  </code></pre>
  
  <p>I believe part of the problem I am having is replacing what is in "domlist" with the new greatest ordered pair and returning that as the answer, i.e. I don't want to append "domlist" with the new greatest ordered pair until I remove the old greatest ordered pair from domlist. </p>
  
  <p>My first loop works fine, it is just the second for loop in defining dominantx where I am having trouble. I am relatively new to Python, so please forgive any simply fixes or errors. I am open to any suggestions that still implement a loop and, of course, any help is greatly appreciated. Thank you!</p>