Get Smallest of Strings Lexicographically

To find the smallest of given List of strings lexicographically in Python, call min() builtin function and pass the strings as arguments or the list of strings as argument to this function.

min() function returns the string that occurs first when the given strings are sorted lexicographically in ascending order.

Examples

In the following program, we shall take a list of string and find the lexicographically smallest string in the list using min() function.

Example.py

myList = ['mango', 'apple', 'orange']
result = min(myList)
print(f'Minimum of given list is {result}.')
Try Online

Output

Minimum of given list is apple.

Conclusion

In this Python Tutorial, we have learnt how to find the smallest string of given list lexicographically, with the help of min() function.