The max() and min() functions can also be used to find the maximum and minimum values in a list of strings. For example, the following code finds the maximum and minimum values in the list
list2:
In this case, the max() function compares the ASCII values of the strings in the list. The ASCII value of
orange is 79, which is the highest in the list. The ASCII value of
kiwi is 75, which is the lowest in the list.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
There are two built-in functions in Python that you can use to find the maximum and minimum values in a list:
max(): Returns the largest value in a list.min(): Returns the smallest value in a list.For example, the following code finds the maximum and minimum values in the list
list1:Python
This will print the following output:
Code snippet
The
max()andmin()functions can also be used to find the maximum and minimum values in a list of strings. For example, the following code finds the maximum and minimum values in the listlist2:Python
This will print the following output:
Code snippet
In this case, the
max()function compares the ASCII values of the strings in the list. The ASCII value oforangeis 79, which is the highest in the list. The ASCII value ofkiwiis 75, which is the lowest in the list.