Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a compound word split by hyphen into two individual words

I have the following list

list1= ['Dodd-Frank', 'insurance', 'regulation']

I used the following to remove the hyphen

new1 =[j.replace('-', ' ') for j in list1]

The result I got

new1= ['Dodd Frank', 'insurance', 'regulation']

The result that Ideally want is

new1= ['Dodd', 'Frank', 'insurance', 'regulation']

How can I accomplish this in the most pythonic (efficient way)

like image 523
venkatttaknev Avatar asked Nov 30 '19 20:11

venkatttaknev


People also ask

How do you separate compound words?

Open Compound WordsWhen adverbs ending in -ly combine with another word, the resulting compound is always spelled as two separate words.

Do hyphens make two words one?

So, once compound words are closed or hyphenated, they are counted as one word. If the compound word is open, e.g., "post office," it is counted as two words.


2 Answers

list1 = ['Dodd-Frank', 'insurance', 'regulation']
new1 = '-'.join(list1).split('-')
print(new1)

Prints:

['Dodd', 'Frank', 'insurance', 'regulation']
like image 137
Andrej Kesely Avatar answered Sep 20 '22 11:09

Andrej Kesely


list2 = []
[list2.extend(i.split("-")) for i in list1] 

list2:

['Dodd', 'Frank', 'insurance', 'regulation']
like image 29
Anil CS Avatar answered Sep 17 '22 11:09

Anil CS