You've got one line of code backwards. Your if statement is effectively saying that if item is greater than Max, set item to Max. You need to flip that to say if item is greater than Max, set Max to item.

if item > Max:
    Max = item
return Max

Also, I'm not an expert in Python, but i think you need to change the List inside your function to match the parameter name, in this case args.

Answer from Kadima on Stack Overflow
🌐
Real Python
realpython.com › ref › builtin-functions › max
max() | Python’s Built-in Functions – Real Python
You can support max() in custom classes by implementing the .__gt__() special method.
🌐
GitHub
gist.github.com › yvan-sraka › 52384523a92bb0910d770f0fdde59bbd
Max function implementation explained in Python - Gist - GitHub
I know you compiled this long ago but I just found out that your implementation is wrong as it will not hold true for all negative numbers in the list. To correct this you should change line 9 to: plus_grand_nombre = liste[0] ... def max(list): if list[1:]: if list[0] > max(list[1:]): return list[0] else: return max(list[1:]) elif not list: return else: return list[0]
🌐
W3Schools
w3schools.com › python › ref_func_max.asp
Python max() Function
Python Examples Python Compiler ... Interview Q&A Python Training ... The max() function returns the item with the highest value, or the item with the highest value in an iterable....
🌐
Unstop
unstop.com › home › blog › python max() function | all use cases with code examples
Python max() Function | All Use Cases With Code Examples
February 12, 2025 - In the example Python program, the max() function compares all the elements in the list iterable object and returns 19 as the largest value. When applied to strings, max() compares them lexicographically (alphabetically).
🌐
Programiz
programiz.com › python-programming › methods › built-in › max
Python max()
max() returns the largest element from an iterable. ... If the items in an iterable are strings, the largest item (ordered alphabetically) is returned. languages = ["Python", "C Programming", "Java", "JavaScript"]
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-max-function
Python - max() function - GeeksforGeeks
July 15, 2025 - Python max() function returns the largest item in an iterable or the largest of two or more arguments.
Top answer
1 of 1
46

Short answer: Use a star to collect the arguments in a tuple and then add a special case for a tuple of length one to handle a single iterable argument.

Source material: The C code that handles the logic can be found at: https://github.com/python/cpython/blob/da20d7401de97b425897d3069f71f77b039eb16f/Python/bltinmodule.c#L1708

Simplified pure python code: If you ignore the default and key keyword arguments, what's left simplifies to:

def mymax(*args):
    if len(args) == 0:
        raise TypeError('max expected at least 1 argument, got 0')
    if len(args) == 1:
        args = tuple(args[0])
    largest = args[0]
    for x in args[1:]:
        if x > largest:
            largest = x
    return largest

There are other nuances, but this should get you started.

Documentation: The special handling for the length one case versus other cases is documented here:

Return the largest item in an iterable or the largest of two or more arguments.

If one positional argument is provided, it should be an iterable. The largest item in the iterable is returned. If two or more positional arguments are provided, the largest of the positional arguments is returned.

More complete version: This includes some of aforementioned nuances like the key and default keyword arguments and the use of iterators instead of slices:

sentinel = object()

def mymax(*args, default=sentinel, key=None):
    """max(iterable, *[, default=obj, key=func]) -> value
    max(arg1, arg2, *args, *[, key=func]) -> value
    
    With a single iterable argument, return its biggest item. The
    default keyword-only argument specifies an object to return if
    the provided iterable is empty.
    With two or more arguments, return the largest argument.
    """
    if not args:
        raise TypeError('max expected at least 1 argument, got 0') 
    if len(args) == 1:
        it = iter(args[0])
    else:
        if default is not sentinel:
            raise TypeError('Cannot specify a default for max() with multiple positional arguments')
        it = iter(args)
    largest = next(it, sentinel)
    if largest is sentinel:
        if default is not sentinel:
            return default
        raise ValueError('max() arg is an empty sequence')
    if key is None:
        for x in it:
            if x > largest:
                largest = x
        return largest
    largest_key = key(largest)
    for x in it:
        kx = key(x)
        if kx > largest_key:
            largest = x
            largest_key = kx
    return largest

# This makes the tooltips nicer
# but isn't how the C code actually works
# and it is only half correct.
mymax.__text_signature__ = '($iterable, /, *, default=obj, key=func)'
Find elsewhere
🌐
ZetCode
zetcode.com › python › max-builtin
Python max Function - Complete Guide
April 11, 2025 - You can make custom objects work with max by implementing the __gt__ special method.
🌐
ThePythonGuru
thepythonguru.com › python-builtin-functions › max
Python max() function - ThePythonGuru.com
January 7, 2020 - The max() function returns the largest of the input values.Its syntax is as follows:max(iterable[, default=obj, key=func]) -> value PARAMETER …
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › max() function in python: syntax, parameters, and examples
max() Function in Python: Syntax, Parameters & Examples
April 1, 2026 - It determines the result by comparing ... max function is used in two common ways: you can pass multiple values directly, or you can pass a single iterable such as a list, tuple, or string....
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › max function in python
Max Function in Python | Examples of Max Function in Python
March 28, 2023 - The third max() call is implemented using a lambda function. In all the examples, we got the same output. Only the way for defining function is changed. The last max() call takes multiple iterables (lists).
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Wikibooks
en.wikibooks.org › wiki › Algorithms › Find_maximum › Python_method_1
Algorithms/Find maximum/Python method 1 - Wikibooks, open books for an open world
Python (2.7 and 3.6) source code. The code needs to be reviewed. def findmax(a): if len(a) == 0: return 0 curr_max = a[0] for i in a: if i > curr_max: curr_max = i return curr_max · Simple example of how to use the function: print(findmax([12, 13, 555, 124, 342])) Output should be: 555 · Another way to implement the algorithm: def imax( iterable, key=lambda x: x ): """returns largest item, as input could take iterator or sequence "key" function will be applied on every item, before comparison is made >>> imax( [12,3,4, 89, 90,88] ) 90 """ current_max = None for x in iterable: if current_max is None or key(x) > key( current_max ): current_max = x return current_max ·
Top answer
1 of 3
3

Here is my implementation:

def max(*args, **kwargs):
    key = kwargs.get("key", lambda x: x)
    if len(args) == 1:
        args = args[0]
    maxi = None
    for i in args:
        if maxi == None or key(i) > key(maxi):
            maxi = i
    return maxi

def min(*args, **kwargs):
    key = kwargs.get("key", lambda x: x)
    if len(args) == 1:
        args = args[0]
    mini = None
    for i in args:
        if mini == None or key(i) < key(mini):
            mini = i
    return mini

A little bit more concise than preview post.

2 of 3
2

The issue you are having is due to the fact that min has two function signatures. From its docstring:

min(...)
    min(iterable[, key=func]) -> value
    min(a, b, c, ...[, key=func]) -> value

So, it will accept either a single positional argument (an iterable, who's values you need to compare) or several positional arguments which are the values themselves. I think you need to test which mode you're in at the start of your function. It is pretty easy to turn the one argument version into the multiple argument version simply by doing args = args[0].

Here's my attempt to implement the function. key is a keyword-only argument, since it appears after *args.

def min(*args, key=None):    # args is a tuple of the positional arguments initially
    if len(args) == 1:       # if there's just one, assume it's an iterable of values
        args = args[0]       # replace args with the iterable

    it = iter(args)          # get an iterator

    try:
        min_val = next(it)   # take the first value from the iterator
    except StopIteration:
        raise ValueError("min() called with no values")

    if key is None:       # separate loops for key=None and otherwise, for efficiency
        for val in it:    # loop on the iterator, which has already yielded one value
            if val < min_val
                min_val = val
    else:
        min_keyval = key(min_val)    # initialize the minimum keyval
        for val in it:
            keyval = key(val)
            if keyval < min_keyval:  # compare keyvals, rather than regular values
                min_val = val
                min_keyval = keyval

    return min_val

Here's some testing:

>>> min([4, 5, 3, 2])
2
>>> min([1, 4, 5, 3, 2])
1
>>> min(4, 5, 3, 2)
2
>>> min(4, 5, 3, 2, 1)
1
>>> min(4, 5, 3, 2, key=lambda x: -x)
5
>>> min(4, -5, 3, -2, key=abs)
-2
>>> min(abs(i) for i in range(-10, 10))
0
🌐
Tutorialspoint
tutorialspoint.com › python › number_max.htm
Python max() Function
The Python max() function is used to retrieve the largest element from the specified iterable. Finding the maximum of two given numbers is one of the usual calculations we perform.
🌐
Python Guides
pythonguides.com › maximum-value-in-python-using-the-max-function
How to Find the Maximum Value in Python Using max()
July 27, 2026 - The second passes the same numbers as five separate arguments, and Python treats them identically. Let’s go through the common data types you’ll work with: numbers (days requested), strings (employee names), and full records pulled from a database. This is the most common use case: days off, ages, hours worked, prices, anything numeric. days_requested = [4, 9, 1, 6, 3] print(max(days_requested))
🌐
GeeksforGeeks
geeksforgeeks.org › max-min-python
max() and min() in Python - GeeksforGeeks
June 17, 2021 - Syntax : max(a,b,c,..,key,default) Parameters : a,b,c,.. : similar type of data. key : key function where the iterables are passed and comparison is performed default : default value is passed if the given iterable is empty Return Value : Returns ...
🌐
Quora
quora.com › How-can-I-rewrite-Pythons-max-function
How to rewrite Python's max function - Quora
Answer (1 of 6): What you wrote doesn’t make sense. The key should be a function of one variable, that will be applied to each element of numbers_list. The whole expression [code]max(numbers_list, key=some_function) [/code]would evaluate to that element of numbers_list for which some_function r...
🌐
Python Academy
python-academy.org › functions › max
max — Python Function Reference
max · Return the largest item in an iterable or the largest of two or more arguments. Python 3.13 · 1 · max(iterable, *[, key, default]) iterable · An iterable object. key · A function to specify a sorting key. default · Default value if the iterable is empty.