python delete empty sub lists of list -
this question has answer here: modification of list items in loop (python) [duplicate] 3 answers i want delete empty sub list, ways failed, other ways successful. why ? worry way: data=[[],[],[],[],[]] rows in data: if len(rows)==0: list.remove(rows) print data the result [[],[]] .it isn't expected result [] the correct way(my friend tell me,thank him): list = [[],[],[],[],[]] a=list(filter(lambda x: [] != x, list)) print the result expected empty list [] avoid iterating on list while doing changes on it: data=[[],[],[],[],[]] rows in data: if len(rows)==0: data.remove(rows) print data instead, create new list: >>> lst = [] >>> data = [[],[],[],[1,2,3]] >>> >>> rows in data: if rows: #if rows not empty list lst.append(rows) >>> lst [[1, 2, 3...