Calculating the maximum value of a list

I am trying with an unknown list :slight_smile:

def what_is_my_max(listunknown):
unknown_list = []
for things in lst:
return unknown_list

Please help

A few points.

  • max() doesn’t require the list to be sorted.
  • sorted() doesn’t sort a list in place. It returns a new list with the items sorted. If you don’t assign a variable to the returned list, it’s lost.
  • lst in your code isn’t defined.
  • Probably no need for unknown_list since your function seems to accept a list as an argument assigned to the parameter, listunknown.
  • Likely, the assignment is to write a function that returns the max value without using the built-in max() method.

You could start by writing a list of numbers on a piece of paper. Then consider the steps that you would take to determine which number is the largest. Write those steps down. Better yet, how would you explain to a child how to find the largest number? Write those steps down. Then consider python code for each step.


If we’re to go by the title, calculating the maximum then it would suggest NOT using the built-in, but writing our own algorithm. If we cannot do that, then how would we ever explain how max() works? Best to work with the naive algorithms and master them before reaching for built-ins that teach us nothing.

So should I use max or create my own algorithm?

For the practice and the mental imaging, write an algorithm.