0

I need to get the string list along with delimiter For example

string= "I am a developer and i need to work on web development"

I am using

re.split("and", string)```

I need to get Output as
**Output**
```I am developer 
and i need to work on web development```
sai
  • 17
  • 3

2 Answers2

0

Here is a simple solution using the str.split function:

string = "I am a developer and I need to work on web development"
delimiter = "and"

string_1, string_2 = string.split(delimiter, maxsplit=1)
string_2 = f"{delimiter}{string_2}" # or string_2 = delimiter + string_2

print(string_1) # I am a developer 
print(string_2) # and I need to work on web development

This clearly relies on the fact that the delimiter is in the string.

Riccardo Bucco
  • 13,980
  • 4
  • 22
  • 50
0

Try this:

>>> s = "I am a developer and i need to work on web development"
>>> s1 = s.replace('and', '\nand')
>>> s1
'I am a developer \nand i need to work on web development'
>>> print(s1)
I am a developer 
and i need to work on web development
>>>