티스토리 뷰

공부

[Python] Split string every nth character?

seunggabi 승가비 2021. 9. 11. 08:53
>>> line = '1234567890'
>>> n = 2
>>> [line[i:i+n] for i in range(0, len(line), n)]
['12', '34', '56', '78', '90']

https://stackoverflow.com/questions/9475241/split-string-every-nth-character

 

Split string every nth character?

Is it possible to split a string every nth character? For example, suppose I have a string containing the following: '1234567890' How can I get it to look like this: ['12','34','56','78','90']

stackoverflow.com

 

'공부' 카테고리의 다른 글

[Java][Spark] dataframe to csv  (0) 2021.09.11
[Java][Spark] rows to dataframe  (0) 2021.09.11
[Python] Split string every nth character?  (0) 2021.09.11
[Linux] check DNS  (0) 2021.09.11
[Java][Spark] add column & default  (0) 2021.09.11
[Java][Spark] pyspark.sql.Row.asDict  (0) 2021.09.11
댓글
댓글쓰기 폼