Python Implementation list Flashback print

Source: Internet
Author: User
Tags python list

def func (ListNode):    listnode.reverse () for         i in ListNode:             print (i) Li = [1,2,3,4,5]func (LI)

Use the Python list function reverse () to flashback the list and then traverse the print, but there is a drawback to changing the order of the original list. Take a look at the following code:

def func (ListNode):     = Listnode[::-1]    for in  array:        print(i)
= [1,2,3,4,5]func (LI)

The above code takes advantage of the attributes of the list, sets the step of the list to-1, sorts the list, and assigns it to an array, traversing the array print.

You can also take advantage of pop properties.

def func (ListNode):    array = ListNode for    i in range (0,len (array)):        value =  array.pop ()        print ( Value) Li = [1,2,3,4,5]func (LI)            

Python Implementation list Flashback print

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.