0
def max_in_list(list):
    for value in list:
        reduce(maxof, list)
    print(list)

This program returns "reduce is not defined" Can anyone explain the reduce function for me?

idjaw
  • 25,487
  • 7
  • 64
  • 83
  • 1
    You need to import `functools` to use reduce: `from functools import reduce` – idjaw Oct 15 '16 at 17:09
  • 1
    Also, don't use `list` as a variable name for your *list*. You are shadowing the built-in `list` and could face issues with your code. – idjaw Oct 15 '16 at 17:10
  • 1
    Also, why are you reimplementing `max`? – ShadowRanger Oct 15 '16 at 17:11
  • 2
    In Python 3, `reduce` was removed from builtins. You can still find it in `functools`, though, as noted by idjaw. Also, you just call `reduce`, but you don't do anything with the result, and you should not do it within the loop. You probably want `return reduce(maxof, lst)`, or, well, just `return max(lst)` – tobias_k Oct 15 '16 at 17:12

0 Answers0