Mastering Python for Networking and Security
上QQ阅读APP看书,第一时间看更新

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']