目录:
1. 找到字符串中的所有数字(python find digits in string)
2. python 生成连续的浮点数(如 0.1, 0.2, 0.3, 0.4, ... , 0.9)(python range() for floats)
内容:
1. 找到字符串中的所有数字(python find digits in string)
方法1:
https://stackoverflow.com/questions/12005558/python-find-digits-in-a-string
name = 'body_flaw_validate_set20191119170917_'
list(filter(str.isdigit, name))
['2', '0', '1', '9', '1', '1', '1', '9', '1', '7', '0', '9', '1', '7']
方法2:
https://www.geeksforgeeks.org/python-extract-digits-from-given-string/
import re
name = 'body_flaw_validate_set20191119170917_'
re.sub("\D", "", name)
'20191119170917'
2. python 生成连续的浮点数(如 0.1, 0.2, 0.3, 0.4, ... , 0.9)python range() for floats
https://stackoverflow.com/questions/7267226/range-for-floats
方法1:
[x / 10.0 for x in range(1, 10)]
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
方法2:
import pylab as pl
pl.frange(0.1,0.9,0.1)
array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
方法3:
import numpy
numpy.linspace(0.1, 0.9, num=9)
array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
3.