Sogou Open source projects: Chinese programming language (based on Python)

The main point of this project is to develop, study, discuss Xiaoyu (milang) programming language it is in Python syntax based, and then improve its grammar, increase direct machine generated code, the advantages of mixed C + +, an increase of register based virtual machine. Interested parties, can join the QQ group: 126707482qq: 9073204...
read(3297) comment(1)

5.7 copy-- simple copy and deep copy object

The assignment statement in the Python is not a copy of the object, it is just to make a binding between the object and the object. For some variable containers, it is sometimes necessary to modify the contents of the container, but it does not affect the previous object. Therefore, this module provides a simple copy and deep copy of the object function. Copy.copy (x) returns a simple copy of the object. Examples: #python 3.4import copy L = [2, 4]x = copy.copy (L) print (x) output results as follows: [2, 4] copy.d...
read(764) comment(0)

5.6 array-- efficient numerical array

This module defines an efficient numerical array of types, mainly including: characters, integers, floating point numbers. Numeric types are similar to the list, the main difference is that the list can be put into different types of elements, while the type array can only be placed in a type of elements. Array type only supports the following types: type character type C Python types occupy the smallest byte remarks'b'signed charint1 'B' unsigned charint1'u'Py_UNICODEUnicode'u'Py_UNICODEUnicode haracter2'h'sig...
read(551) comment(0)

Two bisect-- array of 5.5 points algorithm

This module implements the sorted queue list to maintain the sort after the insertion element. For a list of large quantities of data to see, insert elements and maintain order, the amount of computation is very large. This module implements the bisect algorithm, mainly based on two points algorithm to achieve. Bisect.bisect_left left (a, x, lo=0, hi=len (a) the sequence table a insert element x, to maintain orderly unchanged, return the position of the insertion. Parameter hi and lo is the range of the representation to determine the list, the default is the entire range. If the inserted element X is already in the list a, it is inserted...
read(657) comment(0)

The use of 5.4.1 algorithm to achieve the optimal stack queue

A priority queue is typically use a stack algorithm to achieve, priority queue major difficulties are the following points: 1) sort of stability: how two gifted class to achieve the same return first add the task? 2) in the comparison of the tuple, if (priority, task) on the phase at the same time, there is no comparison of the order of the. 3) if the priority of a task is changed, how do you move it to a new location on the heap? 4) when the task is deleted, how do you find it to be deleted, and delete it from the stack queue? In order to solve the problem in front of three, using the two elements of the list to achieve, this list package...
read(526) comment(0)

5.4 heapq-- heap queue algorithm

This module implements the heap queue algorithm, also known as the priority queue algorithm. Heap queue is a binary tree, and has such characteristics, its parent node value is less than or equal to the value of any of its child nodes, if implemented using array can put their relationship expressed as: heap[k] and heap[k], for all k values are established, the K value from 0 begin calculation. As a comparison, it is considered that the elements that do not exist are infinitely large. The heap queue has a more important feature, and its minimum value is the element in the root: heap[0]. API and textbooks under the two heap algorithm...
read(767) comment(0)

UserDict 5.3.7 object

User defined dictionary class UserDict, which is encapsulated by a dictionary class dict. Mainly used to copy a dictionary of the data, rather than sharing the same data. Class collections.UserDict ([initialdata]) the main simulation of a dictionary. In the class member data, copy a copy of the dictionary data, if you do not provide the initial data, you can save the way. An instance of the UserDict class provides the following properties: data used to hold the member variable in the dictionary. Example: #python 3.4...
read(529) comment(0)

OrderedDict 5.3.6 object

The orderly dictionary is the same function as the dictionary, but it keeps the order of the dictionary to be inserted, and when it needs to traverse the first insertion. Class collections.OrderedDict ([items]) returns a new dict class instance, method of operation support dictionary. Examples: #python 3.4import collections D: {'banana'= 3,'apple': 4,'pear': 1,'orange': 2}od =...
read(617) comment(0)

Namedtuple 5.3.5 () to create the name field of the tuple structure

To add a name to the location of each tuple in a named tuple, and you can access it by name, greatly improve the readability, in order to write clear code and improve the maintainability of the code. In fact, it is like the structure of the C++. Collections.namedtuple (typename and field names, verbose=False, rename=False) returns a new type name typenname tuples. The parameter field_names is a string representation of the element name, each...
read(674) comment(1)

Defaultdict 5.3.4 object

Class collections.defaultdict ([default_factory[,... ") returns a dictionary like object. Defaultdict is a built-in dictionary class dict derived class. It is mainly overloaded with a method __missing__ (key) and add a modified instance variable, it functions and functions with the dict class is the same. The first parameter default_factory is the type that uses it as the default value, because the python is not assigned to the...
read(564) comment(0)

Deque other use

In this section provides a number of other ways to use deque. Provide a UNIX like command tail of function, display a file in a text: def tail (filename, n = 10): 'return to file the last n lines of text' with open (filename) as F: return deque (F, n) such as the deque to calculate a moving average: def moving average (iterab...
read(504) comment(0)

Deque 5.3.3 object

Returned to the a new bidirectional queue class collections.deque ([iterable[, maxlen]]). When input iterators, from left to right is added to the queue. If you do not have an input parameter, create an empty queue. Deque is a data structure with stack and queue characteristics. It supports thread safety, memory optimization, and both ends of the pop-up, insert elements, both from the direction of the pop element is O (1) of the time spent. The built-in data type list also supports related operations, but it is designed to carry out the operation of the fixed element...
read(691) comment(0)

Counter 5.3.2 object

Counter class provides a convenient and rapid statistical tool. Example: #python 3.4import collections CNT = collections.Counter) (for word ['red', blue', 'Red', green ', blue','blue']: cnt[word] + = 1print (CNT) the output is as follows: counter ({'blue':,'r...
read(739) comment(2)

Examples and techniques of ChainMap

To provide some ChainMap the use of occasions and skills: simulation Python seized naming variables mapping chain: #python 3.4import builtinsimport collectionspylookup = collections.ChainMap (locals), globals (), vars builtins ()) print (pylookup) in this example, the local scope name, named global scope and built-in...
read(760) comment(1)

ChainMap 5.3.1 object

The ChainMap class is used to manage multiple mapping objects in order to handle all of the mapped objects as an object unit. The advantage of doing so is to create more than one mapping data in a dictionary, and call the update () function of each map to be faster. At the same time, it can be used to simulate the nested scope and template processing. Class collections.ChainMap *maps ChainMap class can put together a dictionary or other mapping objects, consisting of a single, update the mapping object. If the parameter does not specify any mappings...
read(934) comment(0)

5.2 calendar-- generic date correlation function (4)

The calendar class provides the following function to judge the calendar related content: calendar.setfirstweekday (weekday) set a week in that day as the first day. 0 is said Monday, 6 is said Sunday. Example: #python 3.4import calendar print (calendar.firstweekday () calendar.setfirstweekday calendar.SUNDAY the print (Ca...
read(908) comment(0)
1229 data a total of 82 pagesOne Two Three Four Five ... Next page Shadowe
    personal data
    • visit4276574 times
    • Integral:Fifty-three thousand five hundred and thirty-two
    • Grade
    • Rank:Thirty-first name
    • original1179 articles
    • Reproduced:42
    • Translation:6
    • Comments:1987 article
    Article Archive
    Latest comments