Completing to 2 digits using list comprehension
I need to iterate a range between 0 to 18, but in case the number is smaller than 10 then it should contain 0 (e.g. 03) in the first digit, in order to fit the file name.
files = ["part_000"+i+".parquet" for i in range (0, 19)]
How do I add a condition inside the comprehensions so it would be part-00004 rather than part-0004 (04 instead of 4) etc.?
Solution 1:
You can modify your code as follows:
files = [f"part_{i:05d}.parquet" for i in range (19)]
print(files)