Newbie: Large dictionaries

Fredrik Lundh fredrik at pythonware.com
Fri Feb 23 07:32:03 EST 2001


Mikkel Rasmussen wrote:
> I can also put more than 4 million entries *into* the dictionary. But I can
> only get less than 65.000 back out!
>
> What do you get with: len(dict.keys()) ?

if that reports 65,000, you probably don't have more
than 65,000 *unique* entries.

>>> dict = {}
>>> dict["a"] = 1
>>> dict["a"] = 2
>>> dict["a"] = 3
>>> len(dict)
1
>>> len(dict.keys())
1

> And with a loop like
>
> count = 0
> for elem in dict:
>     count = count + 1
> print count

>>> count = 0
>>> for elem in dict:
...     count = count + 1
...
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: loop over non-sequence

are you sure you're using Python?

> The keys are ordinary words like an ordinary dictionary :-) with an average
> length of about 6 characters.

and what language has four million *unique* words
having six characters and less?

Cheers /F





More information about the Python-list mailing list