Modified print_list to use for_each