title: C# : How to compare Dictionary Values?
body: <p>I have a <code>Dictionary&lt;String,String&gt;</code> as follows</p>
  
  <pre><code> Dictionary&lt;String, String&gt; MyDict = new Dictionary&lt;String, String&gt;();
  </code></pre>
  
  <p>and which contains</p>
  
  <pre><code> MyDict.Add("A", "1010");
   MyDict.Add("B", "1011");
   MyDict.Add("C", "1110");
   MyDict.Add("D", "1010");
   MyDict.Add("E", "1011");
   MyDict.Add("F", "1010");
  </code></pre>
  
  <p>I need to Compare the Dictionary <code>Values</code> and then to add the <code>key</code>s which all having same values</p>
  
  <p>here is My resulting Dictionary</p>
  
  <pre><code> Dictionary&lt;String, List&lt;String&gt;&gt; MyResultDict = new Dictionary&lt;String, List&lt;String&gt;&gt;();
  </code></pre>
  
  <p>And  My code</p>
  
  <pre><code> var XXX = MyDict.ToLookup(X =&gt; X.Value, X =&gt; X.Key);
   MyResultDict = MyDict.ToDictionary(X =&gt; X.Key, X =&gt; XXX[X.Value].ToList());
  </code></pre>
  
  <p>The above code will produce the result like</p>
  
  <pre><code> { "A"     { "A" , "D", "F" } }
   { "B"     { "B" , "E" } }
   { "C"     { "C" } }
   { "D"     { "A" , "D", "F" } }
   { "E"     { "B" , "E" } }
   { "F"     { "A" , "D", "F" } }
  </code></pre>
  
  <p>But my solution is having two problem</p>
  
  <ol>
  <li><p>There exist Duplicate value list ( for the keys <code>D</code> , <code>E</code> and <code>F</code>.)</p></li>
  <li><p>The Value List includes the key.</p></li>
  </ol>
  
  <p>The Expected OutPut is like</p>
  
  <pre><code> { "A"     { "D", "F" } }
   { "B"     { "E" } }
  </code></pre>
  
  <p>i.e There is no need of <code>key C</code> because <code>C</code>'s value is not repeated anywhere.</p>
  
  <p>and there is no need to include <code>keys D , E and F</code> because its already included in <code>A</code>'s and <code>B</code>'s value lists.</p>
  
  <p>How to do this using <code>Linq</code> or <code>Lambda Expression</code>?</p>