社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

AnswerSeeker

AnswerSeeker 最近创建的主题
AnswerSeeker 最近回复了

代码:

list_ = ['25 birds, 1 cat, 4 dogs, 101 ants']
import re  
output = list(map(int, re.findall('\d+', list_[0])))
print(output)

输出:

[25, 1, 4, 101]

说明:

re.findall 返回从左到右扫描字符串的字符串列表,按找到的顺序返回匹配项。

map 对字符串列表中的每个项应用int并返回map对象

list 因为map对象是迭代器,所以将其作为参数传递给工厂方法以创建列表