如何在Python中把一个字符串中的所有数字(保留原来的浮点数或整数类型)提取出来并组成一个列表?
e.g.numbers='2-99.0-99.0-99.0-99.025.7807030.275737725.3490.30323.8190.05122.7650.031...
e.g. numbers = '2 -99.0 -99.0 -99.0 -99.0 25.780703 0.2757377 25.349 0.303 23.819 0.051 22.765 0.031 22.258 0.028 21.976 0.035 22.164 0.036 22.011 0.047 -99.0 -99.0 -99.0 -99.0 21.557 0.118 21.734 0.115 16383 0.2755 969 33.950005 -5.488724 0 -1'
展开
1个回答
展开全部
可以用下面的代码来做
number = '2 -99.0 -99.0 -99.0 -99.0 25.780703 0.2757377 25.349 0.303 23.819 0.051 22.765 0.031 22.258 0.028 21.976 0.035 22.164 0.036 22.011 0.047 -99.0 -99.0 -99.0 -99.0 21.557 0.118 21.734 0.115 16383 0.2755 969 33.950005 -5.488724 0 -1'
array = number.split(' ')
array = [a for a in array if len(a) > 0]
print array
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询