## Thursday, September 2, 2021

Solution Exercise 65: Python algorithm which replaces the words in a list with their lengths.

#### Exercise 65

Given a list of strings, write a Python algorithm allowing which replace the elements of the list with their lengths. Example: if
`` L = ["Python", "Django", "Numpy", "Sympy"]``
, the algorithm returns the list
``[6, 6, 5, 5]``

#### Solution

``````def replaceByLength (L):
# initialization of the searched list
listLength = []

# iterate over the elements of L and replace them with their lengths
for word in L:
listLength.append (len (word))
return listLength

# Example
L = ["Python", "Django", "Numpy", "Sympy"]
print (replaceByLength (L)) # the output is: [6, 6, 5, 5]``````

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 