Usually, you could just use

max(nums)

If you explicitly want to use a loop, try:

max_value = None
for n in nums:
    if max_value is None or n > max_value: max_value = n
Answer from helmbert on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › how to find maximum from a list using a for loop in pythonic way?
r/learnpython on Reddit: how to find maximum from a list using a for loop in pythonic way?
June 27, 2023 -

lst = [1,2,3,4,5]

basically, I want to find max: max(lst)

but I want to use a syntax like this: var = max(item) for item in lst

first, why does this return a generator object instead of throwing some error?

And second, how to do it properly?

Edit: so basically there is a function. I need to compute the max value returned by the function. The function should calculate values from a list of inputs.

So, I need to de this:

var = max(func(item)) for item in lst

I just wanted to know if we can do this in one or two liner?

Discussions

Python- Finding the largest number in a list using forloop or while loop - Stack Overflow
Basically we are given a list of numbers and we are asked to write an algorithm to find the largest number in the list, note: the numbers are not in order and may contain decimals and negative numb... More on stackoverflow.com
🌐 stackoverflow.com
python - Find the greatest (largest, maximum) number in a list of numbers - Stack Overflow
How can I easily find the greatest number in a given list of numbers? See also How do I find the maximum (larger, greater) of 2 numbers? - in that special case, the two values can also be compared More on stackoverflow.com
🌐 stackoverflow.com
for loop - How to find the index of the max value in a list for Python? - Stack Overflow
I have a list, and I need to find the maximum element in the list and also record the index at which that max element is at. This is my code. list_c = [-14, 7, -9, 2] max_val = 0 idx_max = 0 for ... More on stackoverflow.com
🌐 stackoverflow.com
How to calculate min/max values in a list without using the min()/max() functions?
You have the right idea. You don't need to make a new loop, though. Just keep track of the maximum score while the data is being entered. More on reddit.com
🌐 r/learnpython
8
2
February 25, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-find-largest-number-in-a-list
Python Program to Find Largest Number in a List - GeeksforGeeks
Explanation: reduce(lambda x, y: x if x > y else y, a) compares each pair of elements in the list a and keeps the larger one, cumulatively returning the maximum value.
Published   November 11, 2025
🌐
Tutorial Gateway
tutorialgateway.org › python-program-to-find-largest-number-in-a-list
Python Program to find Largest Number in a List - 6 Ways
April 7, 2025 - The built-in max() function returns ... be the largest. Apart from these two, you can use the for loop or while loop to iterate the list items and if statement to find the largest. The max function returns the maximum value in ...
🌐
Delft Stack
delftstack.com › home › howto › python › python max value in list
How to Find Maximum Value in a List in Python | Delft Stack
February 2, 2024 - The Python for loop can be used to find the max value in a list by comparing each value in the array and storing the largest value in a variable. For example, let’s declare an array of random integers and print out the max value.
🌐
Educative
educative.io › answers › how-to-find-the-largest-element-in-an-array-in-python
How to find the largest element in an array in Python
After the loop ends, largest will store the largest element in the list. ... We will use Python’s built-in function max() to solve this problem.
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-3.php
Python: Get the largest number from a list - w3resource
June 28, 2025 - This function will be used to find the maximum number in the list. max = list[ 0 ] -> We assume the list is not empty. This line initializes a variable called max to the first element of the list. for a in list: -> This line starts a loop that ...
🌐
CodeRivers
coderivers.org › blog › how-to-find-max-value-using-for-loop-in-python
Finding the Maximum Value Using a `for` Loop in Python - CodeRivers
January 21, 2025 - my_list = [] max_value = None if my_list: max_value = my_list[0] for num in my_list: if num > max_value: max_value = num print("The maximum value in the list is:", max_value) Use Built-in Functions: While using a for loop is a good way to understand the concept, Python also has built-in functions like max() that can be used to find the maximum value in a sequence more concisely.
🌐
TutorialsPoint
tutorialspoint.com › How-to-find-the-element-from-a-Python-list-with-a-maximum-value
Find Element with Maximum Value in Python List
May 16, 2025 - Following is another example to find the element from a Python list with a maximum value using the sort() method. the_list = [54, 57, 827, 74, 91, 74, 62] the_list.sort() maximum_element = the_list [-1] print("The Maximum element of the given list is: ", maximum_element) This output will be displayed when the program runs- ... In this method, we will not use built-in functions, rather, we use a loop to find the largest element in a list.
🌐
Plain English
plainenglish.io › home › blog › python › how to find minimum and maximum values in a list using python
How to Find Minimum and Maximum Values in a List Using Python
May 25, 2022 - The pseudocode for computing the ... which has the first element of the list posited in it. Create a for loop, which iterates through the length of the list....
🌐
Pierian Training
pieriantraining.com › home › understanding the max python function
Understanding the Max Python Function - Pierian Training
May 28, 2023 - We then use a `for` loop to iterate over each element of the list and compare it to the current maximum value. If the current element is larger than the current maximum value, we update the `max_number` variable to be the current element.
🌐
Medium
medium.com › @thedecoding › how-to-find-the-largest-number-in-a-list-without-max-function-in-python-33f5593798af
How to find the largest number in a list without max function in Python | by The Decoding | Medium
April 25, 2022 - def get_max_from_list(numbers): # Step 1) Initialize candidate to first element in list max_value = numbers[0] # Step 2) Go through all remaining numbers in the list for number in numbers[1:]: # Step 3) Check number is larger than our candidate ...
🌐
FavTutor
favtutor.com › blogs › min-max-python
Python Min & Max: Find largest & smallest values (Or with loop)
November 28, 2023 - The actual minimum and maximum value of the string will be stored in the last value of a small and large variables. Return large and small respectively. ... l=eval(input("Enter a list of numbers")) # [4,7,9,10,45,21,46,67,23] --- input larg = l[0] # initialize with the first value small =l[0] # initialize with the first value for num in l: if num > larg: larg = num if num < small: smallest = num print("Largest:", larg) # Output: Largest: 9 print("Smallest:", small) # Output: Smallest: 1
🌐
W3Schools
w3schools.com › python › ref_func_max.asp
Python max() Function
Python Lists Access List Items Change List Items Add List Items Remove List Items Loop Lists List Comprehension Sort Lists Copy Lists Join Lists List Methods List Exercises Code Challenge Python Tuples
🌐
Replit
replit.com › home › discover › how to find the biggest number in a list in python
How to find the biggest number in a list in Python | Replit
3 weeks ago - It starts by assuming the first element is the maximum, storing its index, 0, in a max_index variable. The loop then iterates through the list, comparing the value at the current index i with the value at the stored max_index.
🌐
Studytonight
studytonight.com › python-howtos › find-maximum-value-in-list-in-python
Find Maximum Value in List in Python - Studytonight
February 2, 2021 - list1 = [3, 2, 8, 5, 10, 6] max_number = max(list1); print("The largest number is:", max_number) ... If the items in the list are strings, first they are ordered alphabetically and then the largest string is returned. string = ["Find", "maximum", ...