Function to determine list max without itertools
PythonList at DancesWithMice.info
Fri Apr 19 05:15:43 EDT 2019
> On 19/04/19 7:23 PM, Sayth Renshaw wrote:
> Set the first item in the list as the current largest.
> Compare each subsequent integer to the first.
> if this element is larger, set integer.
Criticism: (because this does NOT match the code, below!)
- should the algorithm "Compare each subsequent integer to the first" or
is the comparison with 'the current largest', ie 'the largest so-far'?
NB IIRC this was (likely) why it was suggested that you explain the
method in English, first!
> def maxitwo(listarg):
> myMax = listarg
> for item in listarg:
> if item > myMax:
> myMax = item
> return myMax
Now, what happens when the code is tested with various (different) sets
(remember the last question from my previous msg!?)
Once you are happy with the various test-runs, do you have any ideas for
making the code more efficient?
More information about the Python-list