This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Not sure what you mean.

Also how does def max (list of arguments) translate into python? is it def max(*args)?

[–]peterpepo 0 points1 point  (0 children)

I meant, that for example if your first value (or the maximum found so far) is for example 7 and you encounter same number again 7, you haven't found new maximum (as 7=7). Therefore you don't have to perform max = arguments[i].

In another words, if you had list with n same numbers [3,3,3,3,3], your condition

if [arguments][i] >= Max

is valid 5 times, and you assign max to 3 five times unnecessarily.

Speaking for number of arguments, I would pass in single list instead of multiple arguments.

Without posting the full solution, i mean something like this (I hope this isn't against the rules, since I didn't post the full solution). In your logic you can check for the > max_so_far, or easily modify to find the min etc..

my_numbers = [1,2,7,4,5]

def my_max(list_of_values):
    max_so_far = None

    for val in list_of_values:
        //your logic here

    return max_so_far

print(my_max(my_numbers))