Simplify logic in purge_nils.

This was just a complicated way of using the standard library.