HackerRank Text Alignment solution in Python