I am trying to write a sequence to take a one dimensional list (regardless of size) and print it out in 2 columns. So far, what I have keeps returning an "Index out of range" error.
Ideally, I'd like for it to print the [0] index out as the header (which I've written into the sequence already) and then for the rest of the indices to be printed out like this:
- - - - - - - - - - - - - - - - - - - - - - - - -
NAMES
- - - - - - - - - - - - - - - - - - - - - - - - -
Rudolph S. Vena U.
Josef M. Efrain L.
Joye A. Mee H.
Joni M. Tanya E.
Rachelle L. Garrett H.
So far, I have seen a lot of examples of using .zip(*) and other ways of doing something similar but usually involving a 2-dimensional list which I do not have. Does anyone have any idea how this could be improved upon?
spacing = '- ' * 25
data_list = [ "NAMES",
"Rudolph S.",
"Josef M.",
"Joye A.",
"Joni M.",
"Rachelle L.",
"Vena U.",
"Efrain L.",
"Mee H.",
"Tanya E.",
"Garrett H."]
while True:
fname_prompt = input("First Name: ").strip().capitalize()
if fname_prompt == "List" or fname_prompt == "list" or fname_prompt == "LIST":
for item, val in enumerate(data_list):
if item == 0:
print(spacing)
print('{:>27s}'.format(str(data_list[item])))
print(spacing)
else:
if item <= len(data_list):
print('{:<10s}'.format(str(data_list[item]) + '{:>20s}'.format(str(data_list[item +1]))))
else:
break