Re: Function to determine list max without itertools

2019-04-22 Thread Chris Angelico
On Tue, Apr 23, 2019 at 12:45 AM Grant Edwards wrote: > At the very top level _sometimes_ you want to have one single, global, > try/except to catch all exceptions and handle the nofication and exit > in a non-default way. For example: in a GUI application, it's > possible that nobody will see

Re: Function to determine list max without itertools

2019-04-22 Thread Grant Edwards
On 2019-04-20, Michael Torrie wrote: > On 04/19/2019 04:01 AM, Sayth Renshaw wrote: >> def max_try(listarg): >> myMax = listarg[0] >> try: >> for item in listarg: >> if item > myMax: >> myMax = item >> except TypeError: >> print(f'Only

Re: Function to determine list max without itertools

2019-04-19 Thread Michael Torrie
On 04/19/2019 04:01 AM, Sayth Renshaw wrote: > def max_try(listarg): > myMax = listarg[0] > try: > for item in listarg: > if item > myMax: > myMax = item > except TypeError: > print(f'Only numbers are supported, this entry "{item}" was not')

Re: Function to determine list max without itertools

2019-04-19 Thread Rob Gaddi
On 4/19/19 5:34 PM, MRAB wrote: [snip] How would you avoid comparing the initial max with list[0]? By slicing the list? By using 'iter' and 'next'? Do you expect that doing either of those to avoid a single comparison would make it faster? Is a comparison very expensive? You could, of

Re: Function to determine list max without itertools

2019-04-19 Thread MRAB
On 2019-04-20 00:24, DL Neil wrote: On 20/04/19 4:41 AM, Rob Gaddi wrote: On 4/19/19 12:23 AM, Sayth Renshaw wrote: On Friday, 19 April 2019 17:01:33 UTC+10, Sayth Renshaw  wrote: Set the first item in the list as the current largest. Compare each subsequent integer to the first.

Re: Function to determine list max without itertools

2019-04-19 Thread Cameron Simpson
On 19Apr2019 05:38, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: On 4/19/19 4:01 AM, Sayth Renshaw wrote: Now, what happens when the code is tested with various (different) sets of test-data? (remember the last question from my previous msg!?) It fails on any list entry that

Re: Function to determine list max without itertools

2019-04-19 Thread DL Neil
On 20/04/19 4:41 AM, Rob Gaddi wrote: On 4/19/19 12:23 AM, Sayth Renshaw wrote: On Friday, 19 April 2019 17:01:33 UTC+10, 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

Re: Function to determine list max without itertools

2019-04-19 Thread Rob Gaddi
On 4/19/19 12:23 AM, Sayth Renshaw wrote: On Friday, 19 April 2019 17:01:33 UTC+10, 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. def

Re: Function to determine list max without itertools

2019-04-19 Thread Ben Bacarisse
Sayth Renshaw writes: >> Now, what happens when the code is tested with various (different) sets >> of test-data? >> (remember the last question from my previous msg!?) >> > It fails on any list entry that isn't a float or an int, giving a TypeError. > >> Once you are happy with the various

Re: Function to determine list max without itertools

2019-04-19 Thread Dan Sommers
On 4/19/19 4:01 AM, Sayth Renshaw wrote: Now, what happens when the code is tested with various (different) sets of test-data? (remember the last question from my previous msg!?) It fails on any list entry that isn't a float or an int, giving a TypeError. What if the *first* entry isn't a

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
> Now, what happens when the code is tested with various (different) sets > of test-data? > (remember the last question from my previous msg!?) > It fails on any list entry that isn't a float or an int, giving a TypeError. > Once you are happy with the various test-runs, do you have any ideas

Re: Function to determine list max without itertools

2019-04-19 Thread DL Neil
> 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

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
On Friday, 19 April 2019 17:01:33 UTC+10, 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. def maxitwo(listarg): myMax = listarg[0] for item in

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
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. -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-19 Thread DL Neil
On 19/04/19 5:22 PM, Sayth Renshaw wrote: In English rather than Python, how do you find the maximum element in a list? -- Rob Gaddi, Highland Technology Get first 1 item in the list and compare it to the rest. If it is larger than rest its the max. However if another list member is

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
> > In English rather than Python, how do you find the maximum element in a > list? > > -- > Rob Gaddi, Highland Technology Get first 1 item in the list and compare it to the rest. If it is larger than rest its the max. However if another list member is larger it replaces the first item

Re: Function to determine list max without itertools

2019-04-18 Thread Grant Edwards
On 2019-04-18, Rob Gaddi 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

Re: Function to determine list max without itertools

2019-04-18 Thread Rob Gaddi
On 4/18/19 4:35 PM, Sayth Renshaw wrote: It's still overly complicated. 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

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
> > > It's still overly complicated. > 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:

Re: Function to determine list max without itertools

2019-04-18 Thread MRAB
On 2019-04-18 08:39, Sayth Renshaw wrote: Thank you for the advice everyone. The first thing to try is find every place where you update myMax, and This was actually where I was going wrong. I was setting max but then overwriting it with item. Then kept checking item only to return myMax.

Re: Function to determine list max without itertools

2019-04-18 Thread Chris Angelico
On Thu, Apr 18, 2019 at 5:41 PM Sayth Renshaw wrote: > > Thank you for the advice everyone. > > > > > The first thing to try is find every place where you update myMax, and > > This was actually where I was going wrong. I was setting max but then > overwriting it with item. Then kept checking

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
Thank you for the advice everyone. > > The first thing to try is find every place where you update myMax, and This was actually where I was going wrong. I was setting max but then overwriting it with item. Then kept checking item only to return myMax. I went looking for other solutions as I

Re: Function to determine list max without itertools

2019-04-17 Thread DL Neil
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? ...

Re: Function to determine list max without itertools

2019-04-17 Thread 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? > > > > def

Re: Function to determine list max without itertools

2019-04-17 Thread Chris Angelico
On Thu, Apr 18, 2019 at 9:31 AM 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

Function to determine list max without itertools

2019-04-17 Thread Sayth Renshaw
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? def maximum(listarg): items = list(listarg)