Python QuickStart (3)

Source: Internet
Author: User

Data:

The elements of the list are variable and are created with a [] or list ().

The elements of the Ganso are immutable, created with () or tuple ().

The elements of the collection are not repeatable and are created with the {} or set ().

The dictionary is stored k-v, created with dict () or {}.

Del: Delete data structure element or variable by index

===================================================

List

List.append (x) = = = A[len (a):]=[x]

List.extend (L) = = = A[len (a):]=l

List.insert (i,x) #指定位置插入

List.remove (x)

List.pop ([i])

List.index (x)

You can use the list as a stack

Implementing a queue using Collections.deque

1  from Import deque 2 queue = deque (["a","b","C  "])3 queue.append ("D")4 Queue.popleft ()
View Code

===================================================

Functional Programming Tools: Filter (), map (), reduce ()

Filter (Bool_func, sequence) returns an sequence that includes all the elements in the given sequence that return a value of true after all calls to Bool_func (item). (The same type is returned, if possible). If the sequence (sequence) is a string (string) or a tuple (tuple), the return value must be the same type, otherwise it is always list. For example, the following programs can calculate partial primes:

1 def F (x):return and x%3!=02 filter (F,range (2,25))

Map (function, seq1,[seq2 ...]) invokes function (item) in turn for each element and returns the return value as a list. For example, the following program computes the cube:

1 def Cube (x):return x*x*x2 map (Cube,range (1,10))
1 seq = range (8)2def Add (x, y):return x+y3  Map (ADD,SEQ,SEQ)4#ans [0,2,4,6,8,10,12,14]

Reduce (function, sequence) returns a single value, which is constructed by invoking function functions first with the first two elements of the sequence, then invoking the return value and the third argument, and sequentially executing. For example, the following program calculates the sum of integers 1 to 10:

1 def Add (x, y):return x+y2 reduce (Add,range (1,11))

===================================================

Python QuickStart (3)

Related Article

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.