Python – list transformation

You can use a list comprehension (Python 2.6+):

y = ["{0:0>2}".format(v) for v in x]

Or for Python prior to 2.6:

y = ["%02d" % v for v in x]

Or for Python 3.6+ using f-strings:

y = [f'{v:02}' for v in x] 

Edit: Missed the fact that you wanted zero-padding…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)