list - Python Merge line with 1 entry with next line -
with output like...
['aaa', 'bbb', 'ccc', 'ddd'] ['aaa'] ['bbb', 'ccc', 'ddd'] ['aaa', 'bbb', 'ccc', 'ddd'] ['aaa', 'bbb', 'ccc', 'ddd']
i want merge single element aaa next line bbb ccc ddd form: aaa bbb ccc ddd.
my current code is
s in my_input_string.split('\n'): s = ' '.join(s.split()) entries = s.split(" ") if len(entries) < 2: print entries else: print entries[2]
and return correct output until exception, first returns single element, wrong entry, , printing wanted output yet again.
this want
l = [['aaa', 'bbb', 'ccc', 'ddd'],['aaa'],['bbb', 'ccc', 'ddd'],['aaa', 'bbb', 'ccc', 'ddd'],['aaa', 'bbb', 'ccc', 'ddd']] in range(0,len(l)): if(len(l[i]) < 2): l[i] = l[i] + l[i+1] print l
you need concatenate next list if length <2
Comments
Post a Comment