## Tuesday, June 8, 2021

Solution Exercise 53: python algorithm which determines the penultimate index of an element in a list #### Exercise 53

Write an algorithm in Python allowing to determine the penultimate index of an element in a list without using any predefined function in Python. Example if L = [2, 7, 11, 7, 21, 39, 7] and a = 7 the algorithm returns 3.

#### Solution

``````# function which determines the penultimate index of an element in a list
def penultimate (L, a):
# initialization of the index list
lIndex = []
for i in range (0, len (L)):
if L [i] == a:
lIndex.append (i)
return lIndex [len (lIndex) - 2 ]

# Example
L = [2, 7, 11, 7, 21, 39, 7]
a = 7
print (penultimate (L, a)) # the output:  3``````

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 