Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

python 3.x - Regular expression : Remove words with Capital letters

I am trying to write a regular expression for this list:

data= ["Canada is developing country. Fred works as Deputy Manager in Canada.","Rishi is working for Fred in the same company.", "Rita is another employee in AC Corp."]

And I want to delete all the words that starts with an uppercase letter but it should not check the first word of every sentence ** if it has not been anywhere in the whole data list in middle of any sentence ie, it should not check for Rishi , Rita while Canada and Fred should be removed since they have occured later in the middle of the sentence. Appreciated if there is any other faster solution other than regular expressions

The output should be

Output-["is developing country.works as in.","Rishi is working for in the same company.", "Rita is another employee in."]

I tried looking for solution but couldn't find any relevant code. Any help would be appreciated.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Firs you could split each string on ".". Then you could put each string in different lists. Next, you could split each string on " ". Finnaly, you could start checking for capital letters starting from the 1 element of each list instead of 0. Done! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...