<p>我有一个字符串:<code>'51.6251.8750.6951.4651.462626200'</code>,我想得到这样一个列表:<code>['51.62', '51.87', '50.69', '51.46', '51.46', '2626200']</code></p>
<p>所以,基本上,在找到一个点之后,字符串应该被拆分2个位置</p>
<p>现在,我有以下内容,在这里我创建了一个所有点位置的列表,不确定是否是这样</p>
<pre><code>import re
string = '51.6251.8750.6951.4651.462626200'
k = 2
# I couldn't find the position of the dot actually, so I had to replace for something first, it may be unecessary
subString = '-'
replacedString = re.sub('[.]', subString, string)
# create a list with all positions of the substring
subStringPosition = [i.start() for i in re.finditer(subString, replacedString)]
# add k to each element of the subStringPosition
subStringAfterK = [x + k for x in subStringPosition]
</code></pre>
<p>如果有人能帮助我,我将不胜感激</p>
<p>对于不使用<code>re</code>的解决方案:</p>
<pre class="lang-py prettyprint-override"><code>def split(s):
nums = []
while "." in s:
i = s.find(".")
n = s[:i+3]
s = s[i+3:]
nums.append(n)
if s:
nums.append(s)
return nums
</code></pre>