- Mastering Python for Networking and Security
- José Manuel Ortega
- 71字
- 2021-07-16 17:39:52
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']