Learn Python as a beginner and document the process

  1. namedtuple

    Namedtuple creates a coordinate

Namedtuple is a function that creates a custom tuple, specifies the number of tuple elements, and can refer to elements of the tuple by attributes rather than indexes.

Namedtuple makes it easy to define a datatype that has the invariance of a tuple and can be referenced by attributes. The Point object created is a subclass of the tuple.

Isinstance Determines whether it is a subclass

Similarly, if we want to represent a circle with coordinates and radii, we can also use namedtuple:

Circle=namedtuple(‘Circle’,[‘x’,’y’,’r’])

2.deque

A deque test

In addition to implementing list append() and pop(), deque supports appendleft() and popleft(), which makes it very efficient to add or remove elements to the header.

3.defaultdict

Defaultdict test

Defaultdict behaves exactly the same as dict, except that it returns the default if the Key doesn’t exist.

4.OrderedDict

With dict, keys are unordered. When iterating over dict, we can’t determine the order of keys.

To keep keys in order, use OrderedDict:

OrderedDict practice

Note that OrderedDict keys are sorted in the order they were inserted, not the keys themselves:

5.Counter

Counter is a simple Counter:

Counter to practice

Counts the number of occurrences of each character.

At present, learned these several kinds as to the use, after the learning process will slowly experience. Anything wrong is welcome to correct.

If you do meet a good coworker, you’ll be lucky. Come on! Q Group :766610200 Includes Python, PythonWeb, crawler, data analysis and other Python skills, as well as artificial intelligence, big data, data mining, automation and other learning methods. Build from zero to the project development hands-on combat all-round analysis!

Click: Join