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

前端 未结 10 654
长情又很酷
长情又很酷 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:14

    One simple way would be to sort the list first then use indexing.

    Here's a function that would work:

    a = [1,233,12,34]
    
    def find_max(a):
        return sorted(a)[-1]
    

提交回复
热议问题