Trim Whitespace Three Ways

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.5
Write trim_variants(s) that returns a tuple (both, left_only, right_only) where both has whitespace stripped from both ends, left_only has only the leading whitespace stripped, and right_only has only the trailing whitespace stripped.

Examples

Example 1
Input
s = '   hi   '
Output
('hi', 'hi   ', '   hi')
Explanation

strip() removes both sides, lstrip() only the left, rstrip() only the right.

Constraints

  • s may contain spaces and tabs at either end.

Topics

StringsWhitespace Handling

Companies

OracleIBMCapgemini

Hints

Hint 1

`str.strip()`, `str.lstrip()`, `str.rstrip()` are the three tools you need.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.