python结束语句_在python句子结尾处删除句点

I have sentences like this - "this is a test. 4.55 and 5,000."

I want to remove the period at the end of the sentences, but not between numbers. My output has to be - "this is a test 4.55 and 5,000"

I tried the below options, but not getting the required output:

wordList = "this is a test. 4.55 and 5,000."

pattern3 = re.compile("[^\w\d]+")

wordList = pattern3.sub(' ',wordList)

Also tried the below 2:

pattern3 = re.compile("[^\w]|^[0-9]\.[0-9]")

pattern3 = re.compile("[^\w]|^([0-9]/.[0-9]+)")

I don't know where I am going wrong. Can someone give me some pointers? I searched the earlier posts and tried them, but they are not working for my situation.

解决方案

Try a negative lookahead:

\.(?!\d)

What this matches is any period that's not followed by a digit.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python 的异步编程中,async 和 await 是两个关键字,用于定义异步处理的函数和协程。下面是对这两个关键字的简单解释: - async:用于定义一个异步函数,一个异步函数可以被看作是一个协程。 - await:在协程中等待另一个协程或者 Future 对象执行完成。 下面我来简单介绍一下 Python 异步编程的一些概念和使用方法。 协程 协程是一种用户态的轻量级线程,可以在其中执行一些 IO 密集型的任务而不会阻塞整个应用程序。在 Python 中,协程一般使用 async 关键字定义。协程中使用 await 语句可以等待其他协程或者 Future 对象完成。 async/await async 和 await 是 Python 3.5 之后引入的关键字,用于定义协程和等待协程执行完成。async 定义协程,await 等待协程执行完成。 在协程中,如果需要等待其他协程或者 Future 对象执行完成,可以使用 await 语句。await 语句会等待后面的协程或者 Future 执行完成,然后返回执行结果。 async with/async for 除了 async 和 await,Python 3.5 还引入了 async with 和 async for 语法。async with 用于定义异步上下文管理器,async for 则用于定义异步迭代器。 asyncio Python 3.4 引入了 asyncio 模块,用于支持异步编程。asyncio 模块提供了一些协程相关的 API,包括事件循环、协程、任务和 Future。 asyncio 的主要功能是提供一个事件循环,用于调度协程的执行。在事件循环中,使用 run_until_complete 方法可以执行一个协程或者任务。 总结 async 和 await 是 Python 中异步编程的两个关键字,用于定义协程和等待协程执行完成。在 Python 3.5 之后,async 和 await 成为了 Python 异步编程的标准,同时还引入了 async with 和 async for 语法。asyncio 模块提供了一些协程相关的 API,用于支持异步编程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值