Python Practice › String Programs › Program 24

Smallest and largest word

EasyString Programs · 24 of 106

Write a Python program to find the smallest and largest word in a string.

Advertisement
Input
"Learning is a part of life and we strive"
Output
a Learning

Approach

  1. min and max with key=len.

Solution

Python
words = "Learning is a part of life and we strive".split()print(min(words, key=len), max(words, key=len))
Output
a Learning

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs

Leave a Comment