Debug by sending your data structures to a python interpreter instead of printing and eyeballing them.