gpt4 book ai didi

python - 用python逐句拆分列表

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:43 24 4
gpt4 key购买 nike

我有一个句子列表:

['hello', 'I would like to thank you', 'I would like to thank you. By the way']

当我找到“.”时,我需要将每个句子拆分成列表。 .

例如,在上面的例子中,期望的结果是:

['hello', 'I would like to thank you', 'I would like to thank you'. 'By the way']

我在 python 中尝试使用这段代码:

def split_pint(result):
for i in result:
i = re.split(r". ", i)
return result

但是句子没有拆分。

有什么想法吗?

谢谢

最佳答案

使用简单的迭代和str.split

例如:

data = ['hello', 'I would like to thank you', 'I would like to thank you. By the way']

def split_pint(data):
result = []
for elem in data:
result.extend(elem.split(". "))
return result

print(split_pint(data))

输出:

['hello', 'I would like to thank you', 'I would like to thank you', 'By the way']

关于python - 用python逐句拆分列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56147608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com