title: Find all unique pairs of keys of a dictionary
body: <p>If there's a dictionary:  </p>
  
  <pre><code>test_dict = { 'a':1,'b':2,'c':3,'d':4}
  </code></pre>
  
  <p>I want to find pairs of keys in list of tuples like:  </p>
  
  <pre><code>[('a','b'),('a','c'),('a','d'),('b','c'),('b','d'),('c','d')]
  </code></pre>
  
  <p>I tried with the following double iteration</p>
  
  <pre><code>test_dict = { 'a':1,'b':2,'c':3,'d':4}
  result = []
  for first_key in test_dict:
      for second_key in test_dict:
          if first_key != second_key:
              pair = (first_key,second_key)
              result.append(pair)
  </code></pre>
  
  <p>But it's generating the following result  </p>
  
  <pre><code>[('a', 'c'), ('a', 'b'), ('a', 'd'), ('c', 'a'), ('c', 'b'), ('c', 'd'), ('b', 'a'), ('b', 'c'), ('b', 'd'), ('d', 'a'), ('d', 'c'), ('d', 'b')]
  </code></pre>
  
  <p>For my test case ('a','b') and ('b','a') are similar and I just want one of them in the list. I had to run one more loop for getting the unique pairs from the result.  </p>
  
  <p>So is there any efficient way to do it in Python (preferably in 2.x)? I want to remove nested loops.</p>
  
  <p><strong>Update:</strong><br>
  I have checked with the possible <a href="https://stackoverflow.com/questions/464864/how-to-get-all-possible-combinations-of-a-list-s-elements">flagged duplicate</a>, but it's not solving the problem here. It's just providing different combination. I just need the pairs of 2. For that question a tuple of <code>('a','b','c')</code> and <code>('a','b','c','d')</code> are valid, but for me they are not. I hope, this explains the difference.</p>