Python recipe 578375 by Raymond Hettinger (compact, dictionary). Revision 20.
Save space and improve iteration speed by moving the hash/key/value entries to a densely packed array keeping only a sparse array of indices. This eliminates wasted space without requiring any algorithmic changes.