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)
Open Compound WordsWhen adverbs ending in -ly combine with another word, the resulting compound is always spelled as two separate words.
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.
list1 = ['Dodd-Frank', 'insurance', 'regulation']
new1 = '-'.join(list1).split('-')
print(new1)
Prints:
['Dodd', 'Frank', 'insurance', 'regulation']
list2 = []
[list2.extend(i.split("-")) for i in list1]
list2:
['Dodd', 'Frank', 'insurance', 'regulation']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With