Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

joining two strings in a list of strings based, if two specific string occur after one another

I’m trying to combine two strings in a list, where the combination of the terms have a different meaning compared to when they are tokenized individually.

An example of this would be:

['I', 'want','to','join','a','football','team','in','2022']

The goal is to join the strings 'football' and 'team', with a _ if the two terms occur after one another, resulting in this string football_team.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The final list would looks like this:

['I', 'want','to','join','a','football_team','in','2022']

Any help is appreciated as I only get to the point where I can join the whole list.

EDIT:

I have been trying to join terms using this:
Is there a way to combine two tokens from a list of tokens?

Also I have tried this, but it joins every element in the list:
How to concatenate items in a list to a single string?

EDIT 2:

In answer to a question in the comments, "How would one understand which words would hold some meaning?"

I have a pre-defined list of string combinations that need to be merged.

>Solution :

" ".join(['I', 'want','to','join','a','football','team','in','2022']).replace("football team","football_team").split(" ")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading