[Tutor] Projects (fwd)

Ricardo Aráoz ricaraoz at gmail.com
Thu Jan 24 14:20:35 CET 2008


Tiger12506 wrote:
>> Isn't dictionary access faster than list access? Why are three lists
>> 'much more efficient'?
> 
> Oh no, no, no.  Dictionaries are faster when you are *searching through* for 
> a particular value. If you already know the index of the item in the list, 
> lists are much faster.
> 
> Dictionaries are hash based. Somewhere it has to calculate the hash of the 
> key you give it...
> These three lists are more efficient in terms of size/output ratio. It 
> appeared as if the dictionary that was presented as an example was just 
> going to map one to one all of the values from zero to 999,999 (to match my 
> list version capabilities). Not only is that bad programming style, it's 
> just plain unecessary. 

Nope, if you read the code you'll see the only mapping done is up to 20
and then by tens up to 100, that's all.
The same code could be used with a list, you'd only have to change the
exception name.



More information about the Tutor mailing list