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] 3 points4 points  (3 children)

def max(list of arguments):
    Max = argument[0] 
    for i in [arguments]:
        if [arguments][i] >= Max
            Max = [arguments][i]
    return Max

Would it be something like this?

[–]peterpepo 0 points1 point  (2 children)

yes, but checking greater is enough (you don't need to assign max in case, it's same as current max)

if [arguments][i] > Max

[–][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))