Exercise 25
Write a Python program that determines the list of words not containing the letter 'a' in a given text.
Solution
def wordWithout_a (T):
#initialize the list of words which do not contain the letter a
listWordWithout_a = []
# convert text T to a list
L = T.split ()
# browse the words of the list L and find those which do not contain the letter a
for word in L:
if 'a' not in word:
listWordWithout_a.append (word)
return listWordWithout_a
# Example
T = "Python is a high level programming language"
print ("the list of words which do not contain the letter 'a' is:", wordWithout_a(T))
# The output is: the list of words which do not contain the letter 'a' is: ['Python', 'is', 'high', 'level']
Younes Derfoufi
my-courses.net
my-courses.net