rewrite print_list func to be more flexible