best way to remove leading zeros from a tuple like string

Wolfram Hinderer wolfram.hinderer at googlemail.com
Sun May 20 20:09:26 EDT 2018


Am 21.05.2018 um 01:16 schrieb bruceg113355 at gmail.com:
> If I decide I need the parentheses, this works.
>
>>>> "(" + ",".join([str(int(i)) for i in s[1:-1].split(",")]) + ")"
> '(128,20,8,255,-1203,1,0,-123)'
>
> Thanks,
> Bruce

Creating the tuple seems to be even simpler.

 >>> str(tuple(map(int, s[1:-1].split(","))))
'(128, 20, 8, 255, -1203, 1, 0, -123)'

Wolfram



More information about the Python-list mailing list