import re num = 12345678 print ','.join(re.findall("\d{3}", str(num)))
output: 123,456 Where is the '78'? It looks like that solution inserts comma's from left to right instead of from right to left. -- b h a a l u u at g m a i l dot c o m "You assist an evil system most effectively by obeying its orders and decrees. An evil system never deserves such allegiance. Allegiance to it means partaking of the evil. A good person will resist an evil system with his or her whole soul." [Mahatma Gandhi] On Sat, Mar 22, 2008 at 6:17 AM, Kepala Pening <[EMAIL PROTECTED]> wrote: > > import re > > num = 123456789 > > print ','.join(re.findall("\d{3}", str(num))) > > output: > 123,456,789 > > > > > ----- Original Message ----- > From: [EMAIL PROTECTED] > To: tutor@python.org > Date: Fri, 21 Mar 2008 21:49:18 -0700 > Subject: [Tutor] Even More Converter! > > It works perfectly, so I am sure my question will not be hard to answer. > When Python gives me the answer to my conversion, is there a way to create it > so every 3 numbers a comma is inserted? > Such as: 1 mile is 5,280 feet. Instead of 1 mile is 5280 feet. Yes a simple > thing, but something which I believe will make it look better. > Also is there a way to make this so I don't have to go through every > individual line of code and add *insert comma* or something to it, simply > at the top like how the Unit Menu is placed only once there, and yet > applies to the whole document. Thank you > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor