Issue
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
Solution
For every possible index i
, you would print a character from each string of the list. So, for each string x
in the list you would print out x[i]
if x[i]
exists (by checking length of x).
Full Code:
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
Answered By - Mahdee Mushfique Kamal Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.