Jun-03-2020, 10:03 AM
I have a string. I need to find words and change them if it there are over there.
I am trying something like this. But I doesn't work.
I need to get new string something like this.
I am trying something like this. But I doesn't work.
I need to get new string something like this.
When parents go. What do they listen to. Whyvar = 'When parents goWhat do they listen toWhy'
words = ['When', 'Why', 'What', 'How']
def check(a):
s = []
for x in a:
for j in words:
if j in x:
s.append(foo(x))
return s
def foo(a):
first = list(a)[0]
var = list(a)[1:]
new = []
for x in var:
if x.isupper():
new.append('. ')
new.append(x)
else:
new.append(x)
new_string = first + ''.join(new)
return new_string
var = var.split(' ')
print(check(var))How can I do this correctly ?
