Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no way you could have a memory leak with a snippet of code as simple as that, because python uses at least half-way decent garbage collection. One potential issue is that you might be running out of memory (so definitely avoid .readlines for starters; use "for line in my_file" instead); also a dictionary actually uses quite a bit of memory for various reasons -- one is that a dictionary intentionally uses a hash table considerably larger than your actual current set of keys, both to help mitigate collisions but also to be able to quickly add a lot of new keys if needed, with amortized O(1) time per insertion. Since you are getting so close to the end of your file before it dies, one thing you could try is storing your final dict as a 2-tuple of k-tuples, where the first k-tuple contains the k keys you want to store, and the second k-tuple is your k counts for the k keys. This should save some memory, at the expense that in order to do a look-up of my_key in one of your 2-tuples T you'll need to do something like:</p> <pre><code>match_idx = [i for i in xrange(len(T[0])) if T[0][i] == my_key] if len(match_idx) == 0: # no match, do whatever else: #match count = T[1][match_idx[0]] # now do whatever with count </code></pre> <p>The running time for a look up will be linear in the number of keys you have to search through, instead of constant time (although note that hashing to do a dictionary look-up is not a trivial operation, so the constant is bigger than a typical constant for a simpler operation). If you stored your keys in sorted order then you could use binary search to quickly find your key but this would require more code, and i'm assuming you're using python in part because it tends to give short code. However if you are already successfully creating 6 million of your dictionaries, then on average your 7 million dictionaries must not have many keys in them. So if you really want to use python for your data set, this may be one of the only ways to go unless you get a machine with more memory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload