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,
3
  • The output should be like this:9895678452,8562359856,7453951258,7458965236,8745269874, Commented Mar 20, 2017 at 9:27
  • 2
    Edit your question and include the failed attempt at this. Commented Mar 20, 2017 at 9:28
  • Actually I used your link but voted to close, that you cannot do :) Commented Mar 20, 2017 at 9:47

1 Answer 1

2

You can use regular expression

import re
print re.sub("(.{10})", "\\1,", number, 0, re.DOTALL)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.