## Monday, September 27, 2021

Solution Exercise 94 *: python algorithm which tests if the first character is identical to the last

#### Exercise 94 *

Write a Python algorithm which extract from a string text the list of words whose first character is identical to the last. Example if s = "radar number 212", the algorithm returns the list ['radar', '212']

#### Solution

``````# function which tests if the first character is identical to the last
def first_end (s):
if s  == s [-1]:
return True
else:
return False

# Function which determines the list of words whose first character is identical to the last
def list_first_end (s):
# convert the string s to a list:
L = s.split()
# initialization of the searched list
l_first_end = []

for word in L:
if first_end (word):
l_first_end.append (word)
return l_first_end

# Example
print ("The searched list is:", list_first_end (s))
# The output is: The searched list is: ['radar', '212']``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 