Python Forum
Dictionaries and memory error. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Dictionaries and memory error. (/thread-8504.html)



Dictionaries and memory error. - jarrod0987 - Feb-23-2018

Is there a limit on how big a dictionary can be? I am trying to make one of all permutations of 0-9. If I do 0-8 it works fine. If I do 0-9 it gives a long pause them a Memory Error. How do I know what the limit is?

Is there another way to store this? a list was taking way way too long.


RE: Dictionaries and memory error. - buran - Feb-23-2018

why do you want to store all the possible permutations in memory? that is inefficient


RE: Dictionaries and memory error. - jarrod0987 - Feb-23-2018

(Feb-23-2018, 11:48 AM)buran Wrote: why do you want to store all the possible permutations in memory? that is inefficient

So what is the efficient way to be able to try all possible permutations for a variable until you get one that meets the criteria?


RE: Dictionaries and memory error. - buran - Feb-23-2018

use itertools.permutations(). Create iterator, consume it one permutation at a time to work with
this is brute force, so may be slow. there may be more efficient way to solve your problem (we don't know what your problem is)


RE: Dictionaries and memory error. - jarrod0987 - Feb-23-2018

(Feb-23-2018, 12:06 PM)buran Wrote: use itertools.permutations(). Create iterator, consume it one permutation at a time to work with
this is brute force, so may be slow. there may be more efficient way to solve your problem (we don't know what your problem is)

I seemed to have fixed my issue. I tried to create a list in program to store all the permutations but it was just taking forever. Almost instant now. Must have made a bug somewhere.

Anyways, it would be nice to know how to get itertools to feed the permutations into a variable one at a time. How do I do that?


RE: Dictionaries and memory error. - buran - Feb-23-2018

import itertools
for perm in itertools.permutations(range(5), 3):
    print(perm)
this will print all permutations with length 3 for numbers 0-4