如何将由连字符分隔的复合词拆分为两个单独的词 [英] How to split a compound word split by hyphen into two individual words

查看:49
本文介绍了如何将由连字符分隔的复合词拆分为两个单独的词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下列表

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

我使用以下命令删除连字符

I used the following to remove the hyphen

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

我得到的结果

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

理想的结果是

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

我该如何以最pythonic(有效的方式)完成此操作

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

推荐答案

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

打印:

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

这篇关于如何将由连字符分隔的复合词拆分为两个单独的词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆