Oops, I just realized you meant strip instead of split, so here's an itertools.takewhile solution:

from itertools import takewhile

def lstripped(s):
    return ''.join(takewhile(str.isspace, s))

def rstripped(s):
    return ''.join(reversed(tuple(takewhile(str.isspace, reversed(s)))))

def stripped(s):
    return lstripped(s), rstripped(s)

The polyfill for itertools.takewhile is the following:

def takewhile(predicate, iterable):
    # takewhile(lambda x: x<5, [1,4,6,4,1]) --> 1 4
    for x in iterable:
        if predicate(x):
            yield x
        else:
            break
Answer from Shashank on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › python › string_strip.htm
Python String strip() Method
Following is the syntax for Python ... as the argument to the method, the return value will be the string with the leading and trailing occurrences of the letter stripped....
🌐
W3Schools
w3schools.com › python › ref_string_strip.asp
Python String strip() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The strip() method removes any leading, and trailing whitespaces.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › strip() function in python with examples
Strip() Function in Python with Examples
November 6, 2023 - Strip() is a function in the Python library that helps to return the copy of the string after removing the leading and trailing characters, whitespaces, and symbols that have been passed to the strip() function.
🌐
Guru99
guru99.com › home › python › python string strip() function: how to use?
Python String strip() Function: How to use? [Method ...
July 10, 2026 - Python strip() removes leading and trailing characters from a string and returns a clean copy.
🌐
Programiz
programiz.com › python-programming › methods › string › strip
Python String strip()
... chars - specifies the set of ... all leading and trailing whitespaces are removed from the string. The method returns a string after removing both leading and trailing spaces/characters....
🌐
Mimo
mimo.org › glossary › python › string-strip
Python string.strip(): Syntax, Usage, and Examples
Start your coding journey with Python. Learn basics, data types, control flow, and more ... If you don’t pass any arguments, it removes all leading and trailing whitespace. If you pass a string to chars, it removes all characters found in that string from both ends. The original string remains unchanged; strip() returns ...
Find elsewhere
🌐
Hero Vired
herovired.com › learning-hub › topics › strip-function-in-python
Strip Function in Python - Guide with Examples
The strip() function returns a new string by replacing a few or no characters from the old string according to the specified functionality. ... This program doesn’t pass the parameter to the strip function.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-strip
Python String strip() Method - GeeksforGeeks
July 1, 2026 - ... Parameters: chars (optional) - Specifies the characters to remove from the beginning and end of the string. If omitted, whitespace characters are removed. Return Type: A new string with the specified characters removed from both ends.
🌐
Codecademy
codecademy.com › docs › python › strings › .strip()
Python | Strings | .strip() | Codecademy
April 23, 2025 - If omitted, all types of leading and trailing whitespace (spaces, tabs, newlines, etc.) are removed by default. ... Returns a new string with the specified leading and trailing characters removed. Note: .strip...
🌐
Python Academy
python-academy.org › functions › strip
strip — Python Function Reference
strip · Return a copy of the string with the leading and trailing characters removed. Python 3.13 · 1 · str.strip([chars]) chars · The characters to be removed (defaults to whitespace). Examples · Python 3.13 ·
🌐
Scaler
scaler.com › home › topics › python string strip() method
Python String strip() Method - Scaler Topics
February 22, 2024 - The strip() function returns a new string by replacing a few or no characters from the old string according to the specified functionality.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python strip(): usage, examples, and syntax
Python Strip(): Usage, Examples, and Syntax
September 10, 2025 - Learn how to use the strip() method in Python to remove whitespace or specific characters from strings with syntax details and practical examples.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › python string strip() method
Python String strip() Method: Syntax, Examples, and Use Cases
March 29, 2026 - The strip() method is a built-in ... end of a string. It returns a new copy of the string with all leading and trailing characters removed based on the argument provided, defaulting to whitespace....
🌐
freeCodeCamp
freecodecamp.org › news › python-strip-how-to-trim-a-string-or-line
Python strip() – How to Trim a String or Line
January 12, 2022 - phrase = ".....Python !!!" stripped_phrase = phrase.strip(".!") print(stripped_phrase) #output #Python
🌐
Jaro Education
jaroeducation.com › home › blog › strip function in python
Strip Function in Python with Examples 2026
5 days ago - No, the strip() function does not modify the original string because strings in Python are immutable. Instead, it returns a new string with the unwanted characters removed. To update the value, you need to assign the result to a variable.
🌐
Learn By Example
learnbyexample.org › python-string-strip-method
Python String strip() Method - Learn By Example
April 20, 2020 - By adding chars parameter, you can also specify the characters you want to strip. ... The method return a copy of the string with the leading and trailing characters removed.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › strip.html
strip — Python Reference (The Right Way) 0.1 documentation
Returns a copy of the string with the leading and trailing characters removed. ... Optional. String specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; rather, all combinations of its values ...
🌐
Board Infinity
boardinfinity.com › blog › python-string-strip
strip() in Python | Board Infinity
August 19, 2025 - In Python, the strip() is a built-in method, this method returns a copy of the string with the leading and trailing character both removed (according to arguments passed).