#やりたいこと
下記のようなstr型の文字を2文字ずつ取り出したいです。
'123456789'
期待する実行結果
2468
#試したこと
文字を2文字ずつ改行させてみましたが、取り出し方が分かりません。
python
1import itertools 2 3text = '123456789' 4 5def split_text(text, n): 6 7 for i in itertools.count(): 8 s = text[i * n:(i + 1) * n] 9 if s: 10 yield(s) 11 else: 12 break 13 14for l in split_text(text, 2): 15 print(l)
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。