Exercise 47
Write a python program that determines the list of all the words which contains at least one uppercase character in a given text T. Example if T = "Python is a high level programming language. Originally developed by Guido van Rossum in 1989." The program returns the list:
['Python', 'Originally', 'Guido', 'Rossum']
Solution
# creating a function which test if given word contains at least one uppercase character
def testUpercase(s):
# initializing counter
counter = 0
for letter in s:
if letter.isupper():
counter = counter + 1
if counter > 0:
return True
else:
return False
T = "Python is a high level programming language. Originally developed by Guido van Rossum in 1989."
# initializing the list of all the words which contains at least one uppercase character
listUpper = []
# transform the text T to a list
L = T.split()
for word in L:
if(testUpercase(word)):
listUpper.append(word)
# display the list
print(listUpper)
# The output is : ['Python', 'Originally', 'Guido', 'Rossum']
Younes Derfoufi
my-courses.net
my-courses.net