# Python - Find the greatest number in a list of numbers

Is there any easy way or function to determine the greatest number in a python list? I could just code it, as I only have three numbers, however it would make the code a lot less redundant if I could tell the greatest with a built in function or something.

``````foo = [1,2,3]
print max(foo)
``````

Use `max()`

``````>>> l = [1, 2, 5]
>>> max(l)
5
>>>
``````

You can use the inbuilt function `max()` with multiple arguments:

``````print max(1, 2, 3)
``````

or a list:

``````list = [1, 2, 3]
print max(list)
``````

or in fact anything iterable.

``````    #Ask for number input
first = int(raw_input('Please type a number: '))
second = int(raw_input('Please type a number: '))
third = int(raw_input('Please type a number: '))
fourth = int(raw_input('Please type a number: '))
fifth = int(raw_input('Please type a number: '))
sixth = int(raw_input('Please type a number: '))
seventh = int(raw_input('Please type a number: '))
eighth = int(raw_input('Please type a number: '))
ninth = int(raw_input('Please type a number: '))
tenth = int(raw_input('Please type a number: '))

#create a list for variables
sorted_list = [first, second, third, fourth, fifth, sixth, seventh,
eighth, ninth, tenth]
odd_numbers = []

#filter list and add odd numbers to new list
for value in sorted_list:
if value%2 != 0:
odd_numbers.append(value)
print 'The greatest odd number you typed was:', max(odd_numbers)
``````

If you have to find it without using max function then you can follow the code below:

``````    a=[1,2,3,4,6,7,99,88,999]
max= 0
for i in a:
if i > max:
max=i
print(max)
``````
`max` is a builtin function in python, which is used to get max value from a sequence, i.e (list, tuple, set, etc..)
``````print(max([9, 7, 12, 5]))