PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# help arrange characters vertically
# version 1 using s fof loop:
strings = [ "ab", "cd" ] # should be: [ ["a", "c"], ["b", "d"] ]
#strings = [ "ab1", "cd2", 'ef3' ] # should be: [['a', 'c', 'e'], ['b', 'd', 'f'], ['1', '2', '3']]
res = []
for tmp in zip(*strings):
res.append(list(tmp))
print(res)
# version 2 using a list comprehension:
strings = [ "ab", "cd" ] # should be: [ ["a", "c"], ["b", "d"] ]
#strings = [ "ab1", "cd2", 'ef3' ] # shiuld be: [['a', 'c', 'e'], ['b', 'd', 'f'], ['1', '2', '3']]
res2 = [list(tmp) for tmp in zip(*strings)]
print(res2)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run