python - Recursive method to find the minimum number in a list of numbers -


given sample list:

[5, 3, 9, 10, 8, 2, 7] 

how find minimum number using recursion? answer 2.

i found in question paper while doing recursion exercises. can't figure out way solve this. find it, have sort list first , there's nothing recursively. can 1 show me path?

this recursive implementation of min:

l=[5, 3, 9, 10, 8, 2, 7] def find_min(l,current_minimum = none):     if not l:         return current_minimum     candidate=l.pop()     if current_minimum==none or candidate<current_minimum:         return find_min(l,candidate)     return find_min(l,current_minimum) print find_min(l) >>> 2      

take account should not used in real programs , should treated exercise. performance worse built-in minby several orders of magnitude.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -