[Tutor] Anti-Patterns in Python Programming

R. Alan Monroe amonroe at columbus.rr.com
Sat Jul 12 19:05:10 CEST 2014

> what is a hash value?

Some clever person back in the 1950s realized that computers were
better at numbers than names. So they came up with some gimmicks to
convert names to numbers. It was probably something fancier than "a=1,
b=2, etc. Now let's add up all the letters of the person's name to
make a unique number for that person", but that at least gives you an
idea of what's going on.

Instead of hunting through a list of names for John Doe to find his
phone number, just convert John Doe to 2453 or whatever, then jump
directly to the 2453rd slot in an array, and stow/find his phone
number there.

You can probably immediately see a drawback. Two people's names might
add up to the same number. There are two fixes. Come up with a better
names-to-numbers gimmick, or come up with a gimmick like mini-lists at
each number.


More information about the Tutor mailing list