I have a list which is produced by a list comprehension and it sorts the data in stripped
according to groups by finding which strings have a length of 3 and I want to merge them so that are in a single list separately from single length strings.
stripped = ['a,b', 'c,d', 'e', '', 'f,g', 'h', '', '']
lst = [[i.split(',')] if len(i) is 3 else i for i in stripped]
print(lst)
#[[['a', 'b']], [['c', 'd']], 'e', '', [['f', 'g']], 'h', '', '']
I want to produce [[['a', 'b'], ['c', 'd'],['f', 'g']], 'e', '','h', '', '']
instead
How can I achieve this with a Single list-comprehension if possible?
Edit:
accepted @HennyH's answer because of its high efficiency and simplicity