Removing empty sets from lists
This works for any level (recursively):
{Andy, {}, {}, {}, {Jeff, {{}}, Tim}, {}, {Zach, {}}} //. {} -> Sequence[]
(*
{Andy, {Jeff, Tim}, {Zach}}
*)
Or the cryptic
{Andy, {}, {}, {}, {Jeff, {{}}, Tim}, {}, {Zach, {}}} //. {} :> Unevaluated[## &[]]
Assuming "choose the nonempty sets" means to remove Nulls, this can be done with Select
list={Andy, {}, {}, {}, {Jeff, Tim}, {}, {Zach}};
Select[list, UnsameQ[#, {}] &]
{Andy, {Jeff, Tim}, {Zach}}
This is also a prime candidate for DeleteCases
, here's the equivalent of belisarius method for empty lists nested just one level down:
DeleteCases[{Andy, {}, {}, {}, {Jeff, {{}}, Tim}, {}, {Zach, {}}}, {{} ...}, Infinity]
{Andy, {Jeff, Tim}, {Zach}}