Reversing a List

Another interesting operations that we have in lists is the one that offers the possibility of going back to the list through the reverse () method:

>>> protocolList.reverse()>>> print protocolList
['smtp','http','ftp']

Another way to do the same operation use the -1 index. This quick and easy technique shows how you can access all the elements of a list in reverse order:

>>> protocolList[::-1]>>> print protocolList
['smtp','http','ftp']

Get Mastering Python for Networking and Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.