Skip to main content
Tweeted twitter.com/StackMma/status/860149804948754432
added 5 characters in body
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 23
  • 44

Suppose, I have a list-

 data = {{1, 2, 3}, {3, 5, 0}, {8, 9, 3}, {2, 5, 0}}; 

I want to delete second and fourth rowsublists for which third element of the row is zero. I can do this using

 DeleteCases[data,{_,_,0}]; 

How can the same operation be achieved efficiently if the list contains a large number of elements instead of just 3?

Suppose, I have a list-

 data = {{1, 2, 3}, {3, 5, 0}, {8, 9, 3}, {2, 5, 0}}; 

I want to delete second and fourth row for which third element of the row is zero. I can do this using

 DeleteCases[data,{_,_,0}]; 

How can the same operation be achieved efficiently if the list contains a large number of elements instead of just 3?

Suppose, I have a list-

 data = {{1, 2, 3}, {3, 5, 0}, {8, 9, 3}, {2, 5, 0}}; 

I want to delete second and fourth sublists for which third element of the row is zero. I can do this using

 DeleteCases[data,{_,_,0}]; 

How can the same operation be achieved efficiently if the list contains a large number of elements instead of just 3?

Source Link
solphy101
  • 347
  • 2
  • 13

deleting entire row if certain element is zero

Suppose, I have a list-

 data = {{1, 2, 3}, {3, 5, 0}, {8, 9, 3}, {2, 5, 0}}; 

I want to delete second and fourth row for which third element of the row is zero. I can do this using

 DeleteCases[data,{_,_,0}]; 

How can the same operation be achieved efficiently if the list contains a large number of elements instead of just 3?