[Python] 원하는 개수만큼 자르기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
str_eng='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
length=3
result = [str_eng[i:i+length] for i in range(0, len(str_eng), length)]
# ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQR', 'STU', 'VWX', 'YZ']
str_eng='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
length=3
result = [''.join(x) for x in zip(*[list(str_eng[z::length]) for z in range(length)])]
# ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQR', 'STU', 'VWX']
str_eng='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
length=3
result = list(map(''.join, zip(*[iter(str_eng)]*length)))
# ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQR', 'STU', 'VWX']
This post is licensed under CC BY 4.0 by the author.