Python: Recursive function to find the largest number in the list

前端 未结 10 658
长情又很酷
长情又很酷 2020-12-10 21:04

I\'m trying to do a lab work from the textbook Zelle Python Programming

The question asked me to \"write and test a recursive function max() to find the

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 21:13

    Here is my answer, with a one line of code :))

    def max_value(n_list):
        return n_list[0] if len(n_list) == 1 else max(n_list[0], max_value(n_list[1:]))
    

提交回复
热议问题