0
number = ("98956784528562359856745395125874589652368745269874")

I want to add commas to this string as per requirement not as per currency or other denominations, for example in this string I want to add ,(comma) after 10 places i.e number[9] and so on. I tried it with join method but it didn't work

The output should be like this:

9895678452,8562359856,7453951258,7458965236,8745269874,
Jean-François Fabre
  • 131,796
  • 23
  • 122
  • 195

1 Answers1

2

You can use regular expression

import re
print re.sub("(.{10})", "\\1,", number, 0, re.DOTALL)
khelili miliana
  • 3,537
  • 1
  • 14
  • 25