Longest and smallest word in the input string

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
  1. Take a string as input.
  2. Convert the list into a list using split().
  3. From that list find the longest and smallest word using max() and min().
  4. Use the key as len to find them in the min and max functions.
  5. 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
				
			

test whether a passed letter is a vowel or consonant.

most simultaneously repeated characters in the input string.

Leave a Comment