osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

best way to remove leading zeros from a tuple like string


bruceg113355 at gmail.com wrote:

> Looking over the responses, I modified my original code as follows:
> 
>>>> s = "(0000128, 020, 008, 255, -1203,01,-000, -0123)"
>>>> ",".join([str(int(i)) for i in s[1:-1].split(",")])
> '128,20,8,255,-1203,1,0,-123'

I think this looks better with a generator instead of the listcomp:

>>> ",".join(str(int(i)) for i in s[1:-1].split(","))
'128,20,8,255,-1203,1,0,-123'