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']
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.218.45