Python Forum

Full Version: Dictionaries and memory error.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
why do you want to store all the possible permutations in memory? that is inefficient
(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?
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)
(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?
import itertools
for perm in itertools.permutations(range(5), 3):
    print(perm)
this will print all permutations with length 3 for numbers 0-4