-2

I have example data

jkjkjkMr James Jon
lrtrtrMiss Krin Poo
erere\Mrs Lolo Freh

I want cut string behind Mr, Miss, Mrs

text[text.find('Mr')]
>> Mr James Jon

text[text.find('Miss')]
>> Miss Krin Poo

text[text.find('Mrs')]
>> Mrs Lolo Freh

But I don't want find line by line, how can I loop?

ls = ['Mr', 'Miss', 'Mrs']

text[text.find(ls)]
Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
Bella
  • 43
  • 4
  • What do you mean by "But I don't want find line by line, how can I loop?", could you elaborate a bit more? – Minarth Oct 19 '20 at 11:07
  • Could you elaborate on what is the type of your input? are you reading from a file? is it just a plain text variable? is it a dataframe? – Eliran Turgeman Oct 19 '20 at 11:12

1 Answers1

-1

Code

s = ['jkjkjkMr James Jon','lrtrtrMiss Krin Poo', 'erere\Mrs Lolo Freh']
print(s)
new_s = []
for i in range(len(s)):
    if 'Mr' or 'Miss' or 'Mrs' in s[i]:
        new_s.append(s[i][s[i].find('M'):])
print(new_s)

Output

['jkjkjkMr James Jon', 'lrtrtrMiss Krin Poo', 'erere\\Mrs Lolo Freh']
['Mr James Jon', 'Miss Krin Poo', 'Mrs Lolo Freh']
KittoMi
  • 411
  • 5
  • 19