title: Postings list in Python
body: <p>Hi I need to create a postings dict out of a list of unique words tokenised and processed from multiple files. So the final format of the postings dictionary would be:
  {wordid: [0, 1, ...], wordid2:[0, 1, ...]},</p>
  <p>I am really struggling with this, the only code I have right now is:</p>
  <pre><code>    for i in range(len(docids)):
        for word in vocab:
          if word not in postings.keys():
            postings[word] = []
          else:
            postings[word].append(i)    
  </code></pre>
  <p>this just outputs the dictionary with the term and the docids just repeat each other in strange patterns depending on the number of files I've asked it to index.</p>
  <p><strong>Example input and expected output:</strong><br>
  Doc1 = &quot;hello my name is john&quot;, Doc2 = &quot;hi my second name is smith&quot;.<br>
  This would make a vocab list: ['hello', 'my', 'name', 'is', 'john, 'hi', 'second', 'smith'].<br> Each word has a <em>wordid</em> which is just the index of the word</p>
  <p>And a docid: [0, 1]<br> (this just counts the documents and is used in creating the postings list to say: word <em>w</em> occurs in document <em>doc</em>)</p>
  <p>The final output of this example would be:</p>
  <pre><code>postings = {0: [0], 1: [0,1], 2: [0,1], 3: [0,1], 4: [0], 5: [1], 6: [1], 7: [1]}
  </code></pre>
  <p>So this dict shows each wordid(index of each word in vocab) and which document(s) it appears in</p>
  <p>Also the program as a whole is supposed to be ran from the terminal and giving it the directory and number of files as arguments.</p>