A developer is writing a function to reverse each word in a sentence while preserving the original order of the words. For example, 'Hello World' should become 'olleH dlroW'. The current implementation is: def reverse_words(s): return ' '.join(word[::-1] for word in s.split()). This works for simple cases. However, the input may contain multiple spaces between words (e.g., 'Hello World') and tabs. The requirement is to preserve the exact whitespace between words (including tabs and multiple spaces) in the output. Which of the following modifications will achieve this while keeping the approach efficient?
Preserves all whitespace exactly by keeping the separators.
Why this answer
To preserve whitespace, we need to split using a regex that captures the separators, then reverse each word and rejoin. Option C does this: re.split(r'(\s+)', s) splits and keeps the separators, making it easy to reverse non-whitespace parts. Option A loses the exact spacing.
Option B does not preserve tabs. Option D is a manual loop that is error-prone.