Deque two-way queue and deque queue

Source: Internet
Author: User

Deque two-way queue and deque queue

Import collections as condq = con. deque () # Add dq to the right. append (1) print (dq, 'append') # Add dq on the left. appendleft (2) print (dq, dq [0], 'appendleft') # Clear the queue # dq. clear () # print (dq. count (1), 'Count') # Extend the queue dq on the right. extend ([5, 6, 7]) print (dq, 'extend') # extend the queue dq on the left. extendleft ([0, 0, 0]) print (dq, 'extendleft') # obtain the index that appears for the first time. The last two Parameters specify the start and end positions, the print (dq. index (1), 'index') # Insert the element dq at the specified position. insert (1, [2, 2, 2]) print (dq, 'insert') # retrieve and delete the rightmost element print (dq. pop (), 'Pop ') # retrieve and delete the leftmost element print (dq. popleft (), 'popleft ') # output the specified value dq. remove ([2, 2, 2]) print (dq, 'delete') # reverse the order dq. reverse () print (dq, 'reverse') # Add the elements on the right to the left one time by quantity. rotate (3) print (dq, 'rotate') exit ()

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.