title: How to count the documents which contain a specific word?
body: <p>Assuming I have a dict like this:</p>
  
  <pre><code>docDict = {"alpha": ["a", "b", "c", "a", "b"], "bravo": ["b", "c", "d", "c", "d"]}
  </code></pre>
  
  <p>And what I want to do is like calculating "Document Frequency": assuming each dictionary item is a document, and I have a specific word, so how many documents contain that word?</p>
  
  <p>I've seen many posts telling me how to calculate frequency, but here if <code>"a"</code> appears twice in document <code>"alpha"</code>, I just need the count to be 1. So the "frequency" of <code>"a"</code> should be 1, and <code>"c"</code> should be 2.</p>
  
  <p>I know I can iterate the whole documents dictionary, and add the counter when finding the word in a document. Or I can firstly make the words in every document unique, then combine all the documents and count the word.</p>
  
  <p>But I think there's a better way, a more effective way. Any ideas?</p>
  
  <p>BTW, is there any way I can keep the structure of the dict? In this example, I'd like to get a result of <code>{"alpha": {'c': 2, 'b': 2, 'a': 1}, "bravo": {'c': 2, 'b': 2, 'd': 1}</code></p>
  
  <p><strong>Update</strong></p>
  
  <p>If here I have just a list (something like <code>[["a", "b", "c", "a", "b"], ["b", "c", "d", "c", "d"]]</code>), how can I get a result list like <code>[[1, 2, 2, 0], [0, 2, 2, 1]]</code>.</p>
  
  <p>I've got no idea. The point is to expand each list and assure the order of the terms. Thoughts?</p>