Find The Longest And Shortest Strings And Lengths In A Python List
You can the shortest and longest items in a Python list of strings by using `key=len` with the built-in `min()` and `max()` functions.
For example:
Code
=
=
=
Outputs:
Code
Iowa
Pennsylvania
A useful addition is to call `len()` on the results to find the lengths.
For example:
Code
=
=
=
Outputs:
Code
4
12
Short and sweet.
Happy coding.