Function to determine list max without itertools
Grant Edwards
grant.b.edwards at gmail.com
Thu Apr 18 21:55:23 EDT 2019
On 2019-04-18, Rob Gaddi <rgaddi at highlandtechnology.invalid> wrote:
> On 4/18/19 4:35 PM, Sayth Renshaw wrote:
>
>> This is where I have ended up. Without itertools and max its what I got currently.
>>
>> def maximum(listarg):
>> myMax = listarg[0]
>> for item in listarg:
>> for i in listarg[listarg.index(item)+1:len(listarg)]:
>> if myMax < i:
>> myMax = i
>>
>> return myMax
>>
>> How would you simplify it?
>
> In English rather than Python, how do you find the maximum element
> in a list?
Hint: "greater than" is transitive.
--
Grant
More information about the Python-list
mailing list