Oct-14-2017, 04:38 AM
The functions are so short that I would one-line both of them:
This isn't really a question of efficiency, but rather of readability.
def both_ends(string): return string[:2] + string[-2:] if len(string) >= 2 else "" def fix_start(string): return string[0] + string[1:].replace(string[0], "*")An experienced python programmer would have no issue reading either of these. As a beginner it would certainly be easier to understand separated into more lines.
This isn't really a question of efficiency, but rather of readability.