I am making a UI for termux terminal on android.
This code below prints the content of the directory.
It works perfectly fine but the output is not even, ie, irregular spaces between the columns.
I've seen people using format but in my case the end argument value differ on each print.
def display_dir(dir_name):
direc = os.listdir(dir_name)
for index, d in enumerate(direc):
if index % 2 == 0:
print(f"{index}- {d}", end=" " * 10)
else:
print(f"{index}- {d}", end="\n")
but I want perfectly aligned 2 column output.I've tried many things. Is there a short way to do this?
I actually have a solution where I check the longest string and add white spaces for remaining strings but it's not optimal.