python - Formatting Numbers Inside of a String -
currently i'm working api of online game play build tool, , in doing i've encountered problem. api returns json files user. while working on creating class parses these json files me i've realized i'd able format number inside of 1 of them instead of being "585677088.5" it's "585,677,088". easy enough if string contained number string contains bunch of other text well.
here's block of text
loan:0 unpaidfees:-3510000 total:585677088.5
i'm using python this.
the existing code have in place is:
import urllib2 data = urllib2.urlopen("url")
like this:
>>> my_str = """loan:0 ... unpaidfees:-3510000 ... total:585677088.5""" >>> map(lambda x: (x.split(":")[0], int(float(x.split(":")[-1]))), my_str.split("\n")) [('loan', 0), ('unpaidfees', -3510000), ('total', 585677088)]
Comments
Post a Comment