Find The Longest And Shortest Strings And Lengths In A Python List
January 2022
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
PennsylvaniaA useful addition is to call len() on the results to find the lengths.
For example:
=
=
=
Outputs:
4
12Short and sweet.
Happy coding.
end of line