re.compile() turns a regular-expression pattern into a reusable pattern object. Assign it a meaningful name, then reuse it with methods such as split(). Compilation happens once instead of during every repeated operation, improving performance and readability. section 15.3 section 16.1.3
Reuse a splitter
Set splitter = re.compile(r'(\W+)'), then call splitter.split(line.rstrip()) inside a loop. Combining the result with map() and str.join() preserves the pieces while transforming them. section 15.3 section 16.3.1
splitter = re.compile(r'(\W+)')
for line in args.text.splitlines():
print(''.join(map(fry, splitter.split(line.rstrip()))))
Shows the compact reusable form: compile the pattern once, split each line through the pattern object, map a transformation, and join the results. section 15.3
