Here's the implementation:
def find_max(nums):
max_val = nums[0] # Start with first element
for num in nums[1:]: # Check remaining
if num > max_val:
max_val = num
return max_val
Why start with nums[0]? Starting with fails for negative numbers. Starting with negative infinity works but is less intuitive.
Alternative using max():
def find_max(nums):
return max(nums)
Python's built-in is faster (implemented in C) but understanding the manual approach helps you solve variations like "find second largest" where built-ins don't help.