The Deque module is an item in the Python standard library collections, which provides a sequence that can be manipulated at both ends, which means that you can perform add or delete operations before and after the sequence.1. Create the deque
Create a Deque sequence:
From collections import dequed = deque ()
Deque provides a list-like operation method:
D = deque () d. append ('1') d. append ('2') d. append ('3') len (d) d [0] d [-1]
Output result:
3 '1' 3'
Both ENDS Use pop:
D =
Python full stack Development 5. Several Common sorting algorithms and the data structure provided by the collections module, pythoncollections
During the interview, I often encounter some questions about the sorting algorithm. Here, I simply listed
Leetcode updated to 155, this easy question acceptance but not high, I am curious to open it.Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Push (x)-push element x onto stack.
Pop
# ! /Usr/bin/Python # Coding = UTF-8 # Http://docs.python.org/library/collections.html # Count object only 2.7 From Collections Import Counter # Count the number of occurrences of letters Counter ( ' Hello World ' ) Counter ([ ' Red '
Python (data structure and algorithm [1]) and python (advanced tutorial)Splits a sequence into individual variables.
>>> P = () # Break Down tuples or sequences by assigning values >>> x, y = p >>>> x4 >>> y5 >>> data = ['acme ', 50, 91.9, (, 1)] >>>
In the interview, often encounter some of the problem of sorting algorithm, here, I simply listed a few of the most common sorting algorithms for everyone to learn, perhaps the next day interview exactly use, the second half of the article
Python standard library notes (4)-collections module, pythoncollections
This module provides several very useful Python container types1. Container
Name
Function Description
OrderedDict
Dict that maintains the key
Decompose a sequence into a separate variable>>>p = (4,5)# Decompose tuples or sequences by assigning values>>>X, y = P>>>X4>>>Y5>>>data = [' ACME ', -,91.9, ( -,1,1)]>>>Name, shares, prices, date = data>>>Name' ACME '>>>Date -,1,1)>>>Name, shares,
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.