Use the re module.
>>> import re >>> import ast >>> pixels = ['(112, 37, 137, 255)', '(129, 39, 145, 255)', '(125, 036, 138, 255)'] >>> [ast.literal_eval(re.sub(r'\b0+', '', pixel)) for pixel in pixels] [(112, 37, 137, 255), (129, 39, 145, 255), (125, 36, 138, 255)]
re.sub(r'\b0+', '', pixel) helps remove leading zeros. \b matches between a word character and a non-word character, or vice versa, so there must be a word boundary before zero and after the space character or ( .
Update:
>>> pixels = ['(0, 0, 0, 255)', '(129, 39, 145, 255)', '(125, 036, 138, 255)'] >>> [ast.literal_eval(re.sub(r'\b0+\B', '', pixel)) for pixel in pixels] [(0, 0, 0, 255), (129, 39, 145, 255), (125, 36, 138, 255)]