__author__ = 'dikkini@gmail.com'
from itertools import groupby
def lines_filter(iterable):
"""
input:
any iterable
output:
generator or list
"""
wait_chr = False
is_begin = True
#========================================================================================================
# You can delete "groupby" and the result will not change, but will increase the length of the input list.
#========================================================================================================
for item, i in groupby(iterable):
if item:
is_begin = False
if wait_chr:
wait_chr = False
yield ''
yield item
elif not is_begin and not wait_chr:
wait_chr = True
if __name__ == '__main__':
list1 =['','','','i','hgf', '','','','9876','','','7','','9','','',''] # Input list
print [i for i in lines_filter(list1)] # Output to the list