Exercise 44
Write a python program which groups in a list all the words which begin with a capital letter in a given string s.
Example for s = "Python is a high level programming language. Originally developed by Guido van Rossum in 1989." The program should return the list:
["Python", "Originally", "Guido", "Rossum"]
Solution
s = "Python is a high level programming language. Originally developed by Guido van Rossum in 1989."
L = s.split()
# initializing the list all words which begin with a capital letter
word_capital = []
for word in L:
if word[0].isupper():
word_capital.append(word)
# disply result
print("The list of word bgining by capital letter is word_capital = " , word_capital)
#The output is:
# The list of word bgining by capital letter is word_capital = ['Python', 'Originally', 'Guido', 'Rossum']
Younes Derfoufi
my-courses.net
my-courses.net