title: Storing a large dictionary with non-unique key-value pairs
body: <p>I have a large (over a  million characters) text file of this shape:</p>
  
  <pre><code>'abc' 2
  'nmb' 3
  'sds' 5
  'abc' 6
  </code></pre>
  
  <p>As you see, each line has two elements. The pairs on each line are not unique, meaning 'abc' could map to 2 and 3 and probably many more. I need to store this into a suitable data structure that I could save to a file. Later I would like to see for example how many times a string has showed up and how many times it has been mapped to a certain number. I need to be able to do this relatively quickly, otherwise I could just use the file as-is. </p>
  
  <p>I first tried to create a dictionary and store the data using the <code>json</code> library, which was pretty easy and straightforward to do. But then I realized I can not use that because the key-value pairs are not unique and a key can be mapped to several values and the data structure should preserve that. </p>
  
  <p>So given the largeness of the file and the way I want to use it, what is a good way to do this?</p>