join , split question

M

metal

Hello,
i have some text file list such like following format.
i want to change text format to other format.
 i was upload it pastebin sitehttp://elca.pastebin.com/d71261168

if anyone help ,much appreciate thanks in advance

s = """uji708
uhodih
utus29
agamu4
azi340
ekon62
"""

from itertools import cycle
for i, x in zip(cycle(range(3)), s.splitlines()):
print x + ',',
if i == 2:
print

"""
uji708, uhodih, utus29,
agamu4, azi340, ekon62,
"""
 
M

metal

s = """uji708
uhodih
utus29
agamu4
azi340
ekon62
"""

from itertools import cycle
for i, x in zip(cycle(range(3)), s.splitlines()):
    print x + ',',
    if i == 2:
        print

"""
uji708, uhodih, utus29,
agamu4, azi340, ekon62,
"""

yet another version, a little evil

s = """uji708
uhodih
utus29
agamu4
azi340
ekon62
"""

from itertools import *
print '\n'.join(','.join(x for i, x in g) for k, g in groupby(enumerate
(s.splitlines()), lambda (i, x): i/3))
"""
uji708,uhodih,utus29
agamu4,azi340,ekon62
"""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top