In this program, we will take a string as input and find the longest and smallest word in the input string
Steps to solve the program
- Take a string as input.
- Convert the list into a list using split().
- From that list find the longest and smallest word using max() and min().
- Use the key as len to find them in the min and max functions.
- Print the output.
#Input string
string = "we are learning python"
list1 = string.split(" ")
#printing output
print("Longest word: ", max(list1, key = len))
print("Smallest word: ", min(list1, key = len))
Output : When we will run above program we will get following output.
Longest word: learning
Smallest word: we