How to conditonally include elements in a list?