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:
=
=
=
Outputs:
Iowa
Pennsylvania
A useful addition is to call len()
on the results to find the lengths.
For example:
=
=
=
Outputs:
4
12
Short and sweet.
Happy coding.
-- end of line --