1

I have a list/array and I want to string format it. For example,

 a = [1, 2, 3] and output that I want should be 010203

I tried with b = "%.2d %(a)", however, it gives me an error TypeError: %d format: a number is required, not list. Of course, I can understand this error, but, I don't know the other way.

The code should be generic, I mean, when my list is like a = [10, 11, 12, 13], then, it should print the output like 10111213.

Sanchit
  • 3,180
  • 8
  • 37
  • 53

1 Answers1

2
>>> a = [1,2,3]
>>> "".join("%.2d" % i for i in a)
'010203'
>>> a = [10, 11, 12, 13]
>>> "".join("%.2d" % i for i in a)
'10111213'
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195