Function to determine list max without itertools
PythonList at DancesWithMice.info
Thu Apr 18 00:49:11 EDT 2019
On 18/04/19 4:10 PM, Sayth Renshaw wrote:
>>> I have created a function that takes a list as an argument.
>>> Without using itertools I want to compare each item in the list to find the max.
>>> However instead of the max I keep getting the last item in the list. Where is my logic wrong here?
>>> Seems like it should work but doesn't.
>> I'd recommend rethinking your algorithm first, and then thinking about
>> debugging your actual code. You should be able to find the largest in
>> a collection without making many many passes over the items - a single
>> pass should be sufficient.
> Most I am finding either use the max function or itertools. Both of which I am trying not to use so that I actually do it myself.
Did you understand the advice? Have you simply dropped the first-attempt
and gone looking for another canned-solution?
Whilst you seem to be on-the-right-track, there is a definite error in
the algorithm/the code.
What debugging did you perform?
Do you only assume, or can you see example (pertinent) values during
each "pass" (time through the loop)? If not, why not?
More information about the Python-list