Simple compression solution in Python