![Python-courses-python-exercises-python-students-online-courses](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 60
Write a Python algorithm that reverse the order of the elements of a list using the reverse() method. Example if L = ['Java', 'Python', 'PHP', 'C ++'], the algorithm returns the list: ['C ++', 'PHP', 'Python', 'Java']
Solution
def reverseList (L):
# invert the list L
L.reverse ()
return L
# Example
L = ['Java', 'Python', 'PHP', 'C ++']
print (reverseList (L)) # the output is: ['C ++', 'PHP', 'Python', 'Java']
Younes Derfoufi
my-courses.net
my-courses.net