Skip to content
Home » Python program to find words which are greater than given length

Python program to find words which are greater than given length

Below is the Python program to find the words which are greater than given length

def find_words(lst, k):

result = []
for i in lst:
if len(i) > k:
result.append(i)
return result
lst=input("Enter a sentence:")
list1=lst.split()
print(list1)
k=int(input("Enter length of word:"))
long_words = find_words(list1, k)
print(f"Words longer than {k} characters: {long_words}")

Output:

Enter a sentence:Python is interesting
[‘Python’, ‘is’, ‘interesting’]
Enter length of word:3
Words longer than 3 characters: [‘Python’, ‘interesting’]