How can I reverse my_list?

Question

How can I reverse my_list?

Answer

We don’t need to create a new list and then reverse it. Instead, all we need to do is assign the reversed version of my_list to a new variable named backwards. To reverse a list, we can take a look at the example given:

letters = ['A', 'B', 'C', 'D', 'E']
print letters[::-1]

The stride index is all we need to specify.

2 Likes