I am new to Python, and this is probably a very simple question, but I am having trouble figuring it out. I have some raw input that I need to convert. The input is a body of text such as 'ABCDEFGHIJKLMNO'
but in order for me to continue, I need to convert this into a string such as 'ABC DEF GHI JKL MNO'
.
Asked
Active
Viewed 83 times
0

JubJubTumTum
- 9
- 1
-
2Please show the code that you have tried so far. – Jul 09 '13 at 16:49
-
2This could help you http://stackoverflow.com/questions/2231663/slicing-a-list-into-a-list-of-sub-lists – Samuele Mattiuzzo Jul 09 '13 at 16:50
-
`I` is there O_o. I mean, input != output at all (and the input's ordering is quite scrambled anyways) – Samuele Mattiuzzo Jul 09 '13 at 16:52
-
Although `f` is small in the output and there is a `F` between `K` and `L`. – Sukrit Kalra Jul 09 '13 at 16:53
1 Answers
6
>>> s = 'ABCDEFGHIJKLMNO'
>>> ' '.join([s[i:i+3] for i in xrange(0, len(s), 3)])
'ABC DEF GHI JKL MNO'

arshajii
- 127,459
- 24
- 238
- 287