Python Learning Notes

Source: Internet
Author: User

First of all to recommend a very good Python primer site, feel more than the "basic Python" and other books easier to understand, Liao Xuefeng Station, hope to have learning resources students can also communicate a lot. Here's what we learned today:

Here is a summary of some of the most distinctive functions and their applications:

1. Map

Function usage: def func (x):

.......

L=[l0,l1,l2,l3,...]% a list

Lout=map (func,l)% The value output of each element after the Func function transformation is lout

2. Reduce

Function usage: reduce (func,l) =. Func (Func (func (L0,L1), L2), L3),..

Similar iterative usage:

Reduce completes sum:

k=[1,2,3] Kout=sum (k)

def add_ (x1,x2):

Return x1+x2

Kout=reduce (Add_,k)

3, there is a very efficient calculation of the expression: A1,B1=B1,A1+B1 These two operations are simultaneous

4. Generator

In order to solve the problem that the list needs to occupy a large amount of memory space in the large-scale computation, a generator is generated in the listing generation, while the loop calculates

List-generated: H=[x*x for x in range (10)]

Generator: g= (x*x for X in range (10))

Generator output: G.next ()

5. Filter filtering function (self-proclaimed)

Filter (Func,l) func is true output otherwise does not output

6. Sorted function can be customized, which is why Python is a sort of a sharp weapon.

The default is sorted by ASCII size, in order from small to large, the machine by identifying two neighbors compared to the output of 1 is greater than the latter, 1 is the opposite of the rules to sort

Python Learning Notes

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.