gpt4 book ai didi

python-3.x - 在 Python 中从字符串打印特定切片

转载 作者:行者123 更新时间:2023-12-04 07:58:53 25 4
gpt4 key购买 nike

给定下面的字符串,打印“数字”单词的最有效方法是什么。一、二、三,在python中每个字符串的末尾?
TT001AKP0000X000100一个
SS004AKP0000X000100two
PP05AST0000X00010三
...

最佳答案

我会在这里使用正则表达式方法:

inp = ["TT001AKP0000X000100one", "SS004AKP0000X000100two", "PP05AST0000X00010three"]
nums = [re.sub(r'^.*\d+', '', x) for x in inp]
print(nums) # ['one', 'two', 'three']

关于python-3.x - 在 Python 中从字符串打印特定切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66568663/

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