Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

split string into words and separators

def split_words_separators(an_input: str) -> list:
    """Returns two lists, one with words, and one with the separators used in input string"""
    merged = re.split(r"([ ,]+)", an_input)
    # the [::2] is to get the even indexes, which are the words
    # the [1::2] is to get the odd indexes, which are the separators
    return [merged[::2], merged[1::2]]
Source by itsmycode.com #
 
PREVIOUS NEXT
Tagged: #split #string #words #separators
ADD COMMENT
Topic
Name
5+5 =