Make the Python implementation for P3 more general.
More general -> rename.
Fix the printing.