PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# help re-arrange characters
'''
Ali...,
(this reworked code does only take care about re-arranging characters.)
the code that was posted handles the input of the strings using nested for loops, and finally generates a list of individual characters. these are in the same sequence as the input is given. but we are missing the re-arrangement as required. so i would like to take all complexity and redundancy out of the code: (see my explanations below the code. the key point is a slice (7) that is feeded by the for loop and the range() object.
'''
n = 3 # (0)
strings = '' # (1)
for _ in range(n): # (2)
S = input() # (3)
strings += S # (4)
res = [] # (5)
for start in range(0, n): # (6)
res.append(list(strings[start::n])) # (7)
print(res) # (8)
'''
(0) n is given also by an input and describes the array dimensions
(1) we use a string variable to collect the inputs
(2) to get n inputs, we run a for loop with a range() object
(3) we are taking inputs, one at a time
(4) we collect the input strings in the loop and concatenate them to the variable `strings`
(5) we use an empty list to collect the new strings
(6) to get the re-arranged characters we use a for loop
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run