Home > Enterprise >  How do I print my outputs of a for loop in one line ordered by index
How do I print my outputs of a for loop in one line ordered by index

Time:10-24

Is it possible to print my outputs of a for loop in one line and ordered by index: For example: outputs:TAWSG, HUHWO, ETOHO, RHDAD, EOETI, IRCID, SIISE, NTDAA, OYE ----> THEREISNOAUTHORITYWHODECIDESWHATISAGOODIDEA

CodePudding user response:

lst = ['TAWSG', 'HUHWO', 'ETOHO', 'RHDAD', 'EOETI', 'IRCID', 'SIISE', 'NTDAA', 'OYE']

max_len = max([len(x) for x in lst ])

for i in range(max_len):
    for x in lst: 
        if len(x) > i:
            print(x[i], end = '')
print('\n')

Output: THEREISNOAUTHORITYWHODECIDESWHATISAGOODIDEA

  • Related