Python3.2 official documentation-list tool and decimal floating point number calculation

Source: Internet
Author: User

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

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.