I am new to python and am trying to work with lists. how can i get my function to accept a list of integers and then returns the largest integer in the list?
Use the built-in max
function:
>>> L=[2,-7,3,3,6,2,5]
>>> max(L)
6
If you want to use max
in a custom function, you could do this:
def getMaxOfList(L):
return max(L)
I don't know why you would want to do this though, since it provides absolutely no new functionality
If you want to write your own implementation of max
:
def myMax(L):
answer = None
for i in L:
if i > answer:
answer = i
return answer
use max
function:
>>> L=[2,-7,3,3,6,2,5]
>>> L
[2, -7, 3, 3, 6, 2, 5]
>>> max(L)
6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With