I have a nested list of the form
{{{{a, 0},{b, 1},{c, 2}}, {{d, 4},{e, 5},{f, 6}}} ... }
where the $...$ just means it goes on like that. On the innermost level, as you can see, I have pairs of the form {string, number}
. All I want to do is to delete from this nested list the pairs whose number entry is 0
.
For instance, in the above example, I want to delete only the pair {a, 0}
.
I've spent the last two hours reading up on answers on this website and elsewhere on the internet, without managing to successfully apply them to this case. Most commands just return the empty list. I also find it very hard to understand the syntax of pretty much all of the list-related commands.
I should also say that I don't really care about the nested structure being preserved or about speed, since the list isn't too big.
Thank you for your time.
list/.{_, 0} :> Sequence[]
$\endgroup$DeleteCases[list, {_, 0}, ∞]
also works. $\endgroup$Select[#[[-1]] != 0 &][Partition[Flatten[list], 2]]
- without nested structure and not fast :)) $\endgroup$