
Exercise 61
Resume the previous exercise (Exercise60) without using the reverse() method in python.
Solution
def reverseList (L):
# initialization of the inverted list
lReverse = []
# iterate over the elements of the list L and insert them in an inverted way
for item in L:
lReverse.insert (0, item)
return lReverse
# Example
L = ['Java', 'Python', 'PHP', 'C ++']
print (reverseList (L)) # the output is: ['C ++', 'PHP', 'Python', 'Java']
Younes Derfoufi
my-courses.net
my-courses.net