Python Forum
Identify two specific words next to each
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Identify two specific words next to each
#6
My code doesn't recognize "Kind Regards" at all on it's own, it only removes it when it is next to "Vriendelike groete" :

import re
from bs4 import BeautifulSoup
import string


message = '''
Dear Sir

What do you think


Kind regards

Badu Thusong

Direct tel: 021 974 7313 | Email:
[email protected]

Good Morning

We need your input please.


Vriendelike groete/ Kind regards

Badu Thusong

Direct tel: 021 974 7313 | Email:
[email protected]


Dear Boss


How are you

today

Your number

Branch Agency: Meme

Branch Agency Code: 0329271

Thank you for contacting us


Kind regards

Agriculture Contact Centre
'''

for phrase in ['Vriendelike groete/Kind regards', 'Vriendelike groete/ Kind regards']:
    text = message.replace(phrase, '')
print(text)
Output:

Output:
Dear Sir What do you think Kind regards Badu Thusong Direct tel: 021 974 7313 | Email: [email protected] Good Morning We need your input please. Badu Thusong Direct tel: 021 974 7313 | Email: [email protected] Dear Boss How are you today Your number Branch Agency: Meme Branch Agency Code: 0329271 Thank you for contacting us Kind regards Agriculture Contact Centre
(Apr-26-2019, 07:08 AM)perfringo Wrote: My mistake - the order should be reversed, otherwise 'Kind regards' will be replaced on first loop and second phrase will not be matched (as 'Kind regards' part is already removed).

In [1]: message = '\nGood Morning\n\nWe need your input please.\n\n\nVriendelike groete/ Kind regards\n\nBadu Thusong\n\nDirect tel: 021 974 7313 | Email:\nBadu@thus
   ...: ong.com\n\n\nDear Boss\n\n\nHow are you\n\ntoday\n\nYour number\n\nBranch Agency: Meme\n\nBranch Agency Code: 0329271\n\nThank you for contacting us\n\n\nKin
   ...: d regards\n\nAgriculture Contact Centre'                                                                                                                     

In [2]: for phrase in ['Vriendelike groete/ Kind regards', 'Kind regards']: 
   ...:     message = message.replace(phrase, '') 
   ...:      
                                                                                                                                                        
In [3]: message                                                                                                                                                      
Out[3]: '\nGood Morning\n\nWe need your input please.\n\n\n\n\nBadu Thusong\n\nDirect tel: 021 974 7313 | Email:\[email protected]\n\n\nDear Boss\n\n\nHow are you\n\ntoday\n\nYour number\n\nBranch Agency: Meme\n\nBranch Agency Code: 0329271\n\nThank you for contacting us\n\n\n\n\nAgriculture Contact Centre'
Reply


Messages In This Thread
RE: Identify two specific words next to each - by stahorse - Apr-26-2019, 07:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  identify not white pixels in bmp flash77 17 2,724 Nov-10-2023, 09:21 PM
Last Post: flash77
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,888 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,048 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Need to identify only files created today. tester_V 5 4,746 Feb-18-2021, 06:32 AM
Last Post: tester_V
  Need to identify sheet color in excel workbook chewy1418 2 2,575 Feb-14-2020, 03:26 PM
Last Post: chewy1418
  Need help to identify Mersenne Primes, I do need a search pattern. Pleiades 0 1,977 Dec-03-2019, 11:05 PM
Last Post: Pleiades
  Delete specific lines contain specific words mannyi 2 4,216 Nov-04-2019, 04:50 PM
Last Post: mannyi
  Syntax Error : I can't identify what's wrong! caarsonr 11 6,424 Jun-10-2019, 11:18 PM
Last Post: Yoriz
Photo How to Extract Specific Words from PDFs with Python danvsv 1 4,564 Jan-17-2019, 11:07 AM
Last Post: Larz60+
  Compare all words in input() to all words in file Trianne 1 2,801 Oct-05-2018, 06:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020