8.7 list Tool
Many data structure requirements can be met through the built-in list type, but sometimes you need to select an implementation for different performance choices.
The Array module provides an array object for the image list. It can only store similar data and is more concise. The following example shows an array of numbers. Storage is two bytes of unidentified binary data, rather than each 16-byte value in the normal list of python objects.
>>> From array import array
>>> A = array ('h', [4000, 10,700,222 22])
>>> Sum ()
26932
>>> A [1: 3]
Array ('h', [10,700])
The Collections module provides a list object similar to the method depue (), which can be added and deleted more quickly from the left, but is slow in the intermediate query. These objects are suitable for queue and breadth-first queries.
In addition to the List Implementation, the standard library also provides other tools, such as the bisect module that processes the sorting list.
>>> Import bisect <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Pj4 + forward + CjxwPj4 + forward + nOqrv509rV/forward/K/aGj1 + forward/backward + forward + CjxwPj4 + forward + CjxwPj4 + signature + CjxwPj4 + signature + yq69 + NbGxKO/weight + weight/2o7o8L3A + weight + 1zbO78tXfxuTL + weight + bCC/weight/M8L3A + weight + authorization + vSqr/Y1sbK/authorization + NbGuKG148r9srvNrL/JxNy1vNbCsrvNrLbuveG5 + 6GjyOe5 + authorization/authorization = "http://www.2cto.com/uploadfile/Collfiles/20140519/20140519090801164.jpg" alt = "">
The Decimal module provides high precision for arithmetic operations.
>>> From decimal import *
>>> Round (Decimal ('0. 70') * Decimal ('1. 05 '), 2)
Decimal ('0. 74 ')
>>> Round (. 70*1.05, 2) 0.73