# Solution Exercise 47: python algorithm that determines the list of all the word with at least on uppercase

Feb 24, 2023

#### Exercise 47

Write a python algorithm 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

```def find_uppercase_words(text):
words = text.split()  # split the text into words
uppercase_words = [word for word in words if any(c.isupper() for c in word)]
return uppercase_words

# Example usage:
T = "Python is a high level programming language. Originally developed by Guido van Rossum in 1989."
uppercase_words = find_uppercase_words(T)
print(uppercase_words)
# Output:['Python', 'Originally', 'Guido', 'Rossum']```

Explanation:

1. The find_uppercase_words() function: takes a string text as input and returns a list of words containing at least one uppercase character.
2. The split() method: convert the text into a list of words.
3. Then, we use a list comprehension: to filter out words that do not contain any uppercase characters.
4. For each word in the list of words: we check if any character in the word is uppercase using the isupper() method.
5. If at least one character is uppercase: we include the word in the uppercase_words list.
6. Finally: we return the uppercase_words list.

Younes Derfoufi
my-courses.net