Housekeeping
string_play.py
has a point value of 25. If I get a bunch of these, I will beging scoring them.- I have graded all
print_practice
submissions as of 8:45A today. Keep 'em coming. If you get it in by lunchtime, you can have it back today. - There will be Q3 on Thursday. It will be over the readings on sequences, lists, and tuples.
Hashing
Delicious Corned Beef Hash
What's the idea? A hash function is a function whose domain is some set of objects and whose codomain is the integers. Hash functions are used in a variety of contexts.
A perfect hash function is one which associates different domain values with different integers. Part of the problem is the F-word, "finite." In practice, this is not attained but a well-defined hashing scheme will minimize these so-called "collisions."
Hash functions must be mathematical functions; i.e. the same input yields the same output every time. This is the consistency specification.
A good hash function is basically impossible to invert. Given the output of the hash function, it should be nearly impossible to determine the input. Hence their usefulness as a security measure.
- Passwords: When you log in over a network, your pasword is hashed. Authetication occurs by matching the hashed value of your password against the hashed value that is stored in the host's system files.
- Data Structures: We will learn how this works today in Python.
Hashable Objects in Python Mutable
objects are not hashable. You might ask why. Hash function usually
depend on object state. So if state changes, the hash function
could change, violating the consistency specification. How do you
see if something is hashable? Call the hash
function
on it.
Sets
A Little Math
Stupid Set (You will later write this in Java)
Hashing and Sets Here is why retrieval from a set is fast.