n = 136462380542525933949347185849942359177
how to split it into group of 3 digits? the result that i want is
136, 462, 380, ..., 177
n = 136462380542525933949347185849942359177
how to split it into group of 3 digits? the result that i want is
136, 462, 380, ..., 177
A regex one-liner.
import re
# match 3 digits or 1-3 digits at the end
ls = re.findall(r"(\d{3}|\d{1,3}$)", str(n))
Result
print(ls)
# ['136', '462', '380', '542', '525', '933', '949', '347', '185', '849', '942', '359', '177']
This solution also extracts the last 1 or 2 digits if n has (3m+1) or (3m+2) digits.
n = 136462380542525933949347185849942359177
s = str(n)
a = []
for i in range(0, len(s) - 2):
a.append(s[i: i + 3])
print(a)