On 11月6日, 上午8时34分, metal <metal...@gmail.com> wrote: > On 11月4日, 下午5时39分, elca <high...@gmail.com> wrote: > > > 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 > > -- > > View this message in > > context:http://old.nabble.com/join-%2C-split-question-tp26193334p26193334.html > > Sent from the Python - python-list mailing list archive at Nabble.com. > > 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 """ -- http://mail.python.org/mailman/listinfo/python-list