## Saturday, October 17, 2020

Solution Exercise 3 : python algorithm which determines the list of odd index element and the list of even index element #### Exercise 3

write a python algorithm as function that takes as parameter a list l and returns a tuple of two lists (l_old , l_even) where l_even is make up by the elements of l of even index and l_old is make up by the list element of odd index. Example: if:
``L = ["Python" , "Java" , "C++" , "C#" , "VB.Net" , "Javascript"]``
the algorithm return :
``(['Python', 'C++', 'VB.Net'], ['Java', 'C#', 'Javascript'])``

#### Solution

``````def odd_event(L):
# getting the length of list
n = len(L)
# initializing the even an
l_odd = []
l_even = []

# build the even and odd list
for i in range(0 , n):
if( i%2 == 0):
l_even.append(L[i])
else:
l_odd.append(L[i])

return (l_even , l_odd)

# Example
L = ["Python" , "Java" , "C++" , "C#" , "VB.Net" , "Javascript"]
print(odd_event(L))
# The output is : (['Python', 'C++', 'VB.Net'], ['Java', 'C#', 'Javascript'])``````

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 