Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,问题是给定一个分数eg:1/3,答案0.3333333应该表示为,0.(3) 并且我已经想出了一种方法来分割字符串,当它的单个数字重复时:0.23255550.232(5)
eg:1/3
0.3333333
0.(3)
0.2325555
0.232(5)
使用re.findall(r'^(.+?)((.)\3+)$', '42344444' )[0][:-1](忽略0.数字之前的)
re.findall(r'^(.+?)((.)\3+)$', '42344444' )[0][:-1]
0.
但我想知道如果模式0.324324324..要得到如何做到这一点0.(324)
0.324324324..
0.(324)
在重复部分+之后添加:.
+
.
>>> re.findall(r'^(.+?)((.+)\3+)$', '42344343434' )[0][:-1] ('42344', '343434')