Function to determine list max without itertools

DL Neil PythonList at
Fri Apr 19 05:15:43 EDT 2019

 > On 19/04/19 7:23 PM, Sayth Renshaw wrote:

In English:

>   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!

In code:

> def maxitwo(listarg):
>      myMax = listarg[0]
>      for item in listarg:
>          if item > myMax:
>              myMax = item
>      return myMax

Well done!

Now, what happens when the code is tested with various (different) sets 
of test-data?
(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?
Regards =dn

More information about the Python-list mailing list