Python string delete -


i've got 2 problems:

1.i have string , want function searches a$ first occurrence of b$ , returns characters of a$ before first occurrence of b$ :

input: mississippi,p ==> output==>mississi

i made program removes string that

word=input("add word: ") m=input("add char:  ") import re removed=word.replace(m,"") print(removed) 

input:mississippi ==> output:mississii

i want delete last "i"

2.another problem string , want split given string (a$) substrings each time character b$ found.

why import re? u can use re.sub:

import re  word=input("add word: ") m=input("add char:  ")  result = re.sub('[{0}{1}]'.format(m.upper(), m.lower()), '', word) print result 

Comments