Answers for "split string by separator python"

41

separate a string in python

spam = "A B C D"
eggs = "E-F-G-H"

# the split() function will return a list
spam_list = spam.split()
# if you give no arguments, it will separate by whitespaces by default
# ["A", "B", "C", "D"]

eggs_list = eggs.split("-", 3)
# you can specify the maximum amount of elements the split() function will output
# ["E", "F", "G"]
Posted by: Guest on May-05-2020
0

spliting the text to lines and keep the deliminaters python

raw_lines = re.split('(?<=!)|(?<=.)|(?<=?)', text)
Posted by: Guest on September-05-2021

Python Answers by Framework

Browse Popular Code Answers by Language