Skip to main content
reformatted code for better readability
Source Link
gwr
  • 13.6k
  • 2
  • 48
  • 82
DeleteCases[list = {{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}};

DeleteCases[ list , {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0,list 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}list /. {0 ..} :> Sequence[]
 
(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0,list 0}}, x \[Function] FreeQ[x, {0 ..}]]] ]

(* assuming no negative integers *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0,list 0, 0,Total 0}},@ Total@## != 0 &]
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]
 
(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, x \[Function] FreeQ[x, {0 ..}]]

(* assuming no negative integers *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &]
list = {{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}};

DeleteCases[ list , {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[ list , Except@{0 ..}]

(* or *)
list /. {0 ..} :> Sequence[]
 
(* using select *)
Select[ list , x \[Function] FreeQ[x, {0 ..}] ]

(* assuming no negative integers *)
Select[ list , Total @ # != 0 &]
deleted 2 characters in body
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]
 
(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@#x !=\[Function] FreeQ[x, {0 &]..}]]

(* in fact select can be usedassuming inno thisnegative wayintegers *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, 
 {0, 0, 0, 0}}, x \[Function]Total@# FreeQ[x,!= {0 ..}]]&]
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]

(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &]

(* in fact select can be used in this way *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, 
 {0, 0, 0, 0}}, x \[Function] FreeQ[x, {0 ..}]]
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]
 
(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, x \[Function] FreeQ[x, {0 ..}]]

(* assuming no negative integers *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &]
added 101 characters in body
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]

(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &] 

(* in fact select can be used in this way *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, 
{0, 0, 0, 0}}, x \[Function] FreeQ[x, {0 ..}]]
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]

(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &]
DeleteCases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, {0 ..}]
(* {{12, 1, 23, 4}, {34, 67, 5, 60}} *)

(* this also results in the same answer *)
Cases[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Except@{0 ..}]

(* or *)
{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}} /. {0 ..} :> Sequence[]

(* using select *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, {0, 0, 0, 0}}, Total@# != 0 &] 

(* in fact select can be used in this way *)
Select[{{12, 1, 23, 4}, {0, 0, 0, 0}, {34, 67, 5, 60}, 
{0, 0, 0, 0}}, x \[Function] FreeQ[x, {0 ..}]]
added 117 characters in body
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43
Loading
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43
Loading