Python - Smallest Length String Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report To identify the smallest string by length in a list, we compare the lengths of all strings and select the shortest one.Using min()The most efficient way to do this is by using the min() function with the key parameter. This method directly calculates the smallest string based on its length, avoiding the need for explicit looping. Python li= ['gfg', 'is', 'best', 'for', 'geeks'] # Finding the smallest string by length res = min(li, key=len) print(res) Outputis Using sorted()sorted() function sorts the entire list based on string lengths and the smallest string is the first element. Python li = ['gfg', 'is', 'best', 'for', 'geeks'] res = sorted(li, key=len)[0] print(res) Outputis Explanation:For the list li, the lengths are: 'gfg' (3), 'is' (2), 'best' (4), 'for' (3), and 'geeks' (5).Sorting the list by length using sorted(li, key=len) results in ['is', 'gfg', 'for', 'best', 'geeks'].The first element, 'is', is the shortest string in li.Using reduce()reduce() function from the functools module can be used to find the smallest string by length in a list. It works by iteratively applying a custom function to pairs of elements, reducing the list to a single result. Python from functools import reduce li= ['gfg', 'is', 'best', 'for', 'geeks'] # Reducing the list to the smallest string res = reduce(lambda x, y: x if len(x) < len(y) else y, li) print(res) Outputis Explanation:reduce():This compares two elements at a time using a lambda function.lambda function: This checks the lengths of the strings and retains the smaller string.This process continues for all elements in the list li , comparing them one by one, and finally returns the smallest string.Using loopThis is the brute method in which we perform this task. In this, we run a loop to keep a memory of the smallest string length and return the string with min length in list. Python li = ['gfg', 'is', 'best', 'for', 'geeks'] # Initialize with a very high value min_len = float('inf') res = "" # Iterate through the list for ele in li: if len(ele) < min_len: # Compare length with the current minimum min_len = len(ele) # Update minimum length res = ele # Update the result with the current smallest string print(res) Outputis Explanation:if len(ele) < min_len: The length of the current string is compared with the current minimum length . If the current string's length is smaller, the condition is True.min_len = len(ele): When the condition is True, min_len is updated to the length of the current string. Create Quiz Comment M manjeet_04 Follow 0 Improve M manjeet_04 Follow 0 Improve Article Tags : Python Python Programs Python list-programs Python string-programs Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like