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
  • 137,073
  • 23
  • 153
  • 219

1 Answers1

2

You can use regular expression

import re
print re.sub("(.{10})", "\\1,", number, 0, re.DOTALL)
khelili miliana
  • 3,730
  • 2
  • 15
  • 28