[Solved] python3 group items in list seperated by at least three empty items
This should work for you lst = [‘a’,’b’,’ c’, ”, ”, ”, ‘d’,’e’,’f’,”,’k’,’j’] res_lst = [] res_str=”” for i, item in enumerate(lst): res_str += item # Add current item to res_str # If next 3 items result is an empty string # and res_str has value if not ”.join(lst[i+1:i+3]) and res_str: res_lst.append(res_str) res_str=”” print(res_lst) Note: … Read more