4
a_list = [ ["a", ""], ["b", "2"] ] 

I have a list of lists as written above. Any suggestions on how to remove the row that contains an empty element (in this case the first list), without using pandas, so it returns:

a_list = [ ["b", "2"] ] 

2 Answers 2

4

Try:

a_list = [["a", ""], ["b", "2"]] a_list = [l for l in a_list if "" not in l] print(a_list) 

Prints:

[['b', '2']] 
Sign up to request clarification or add additional context in comments.

Comments

0

To check at specific index too

Here in your case you're check list[xx][1] index

solution-1

#Devil a_list = [["a", ""], ["b", "2"]] a_list = [l for l in a_list if l[1] != ""] print(a_list) 

solution 2

Use another array and append the data init

new = [] for i in l: if i[1] != "": new.append(i) print(new) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.