数値をカンマ付き数字に変換(commify)
http://pleac.sourceforge.net/pleac_python/numbers.html
から。
def commify(amount): amount = str(amount) firstcomma = len(amount)%3 or 3 # set to 3 if would make a leading comma first, rest = amount[:firstcomma], amount[firstcomma:] segments = [first] + [rest[i:i+3] for i in range(0, len(rest), 3)] return ",".join(segments)
検索したところ、正規表現版が多い。