How do I output the names of a nested list that correspond to their elements? As in this example, I want to output if ("cat") then "foo" , if("dog&quo