Compress String In Python Function