01-python Supplements

Source: Internet
Author: User

List Review
Append (x) Chase to the end of the chain
Extend (L) append a list equivalent to + =
Insert (I,X) inserts x at position I
Remove (x) deletes an element with a value of X if no exception is thrown
Sort () directly modifies the list to a sorted
Sorted (L) returns the sorted L

GANSO data structures that cannot be modified once initialized are faster than the list
Set (set) unordered, non-repeating set of elements is not guaranteed to be ordered
Dictionary (dict) keyword immutable type such as String integer only contains ganso of immutable objects

About the very powerful dictionary function we can do a lot of things like

def leijia (x, y):    a = 0 for    i in Xrange (x,y+1):        A + = i    return adef plus (x, y):    return  X+ymatruix = {    ' + ':p LUs,    ' Leijia ': Leijia,}def size (x,oper,y):    return Matruix[oper] (x, y) print (Size (1, ' Leijia ', 2))

We can do a switch case mode

#filter

A = [1,2,3,4]

Filter (Lamda x:x%2,a)

[1,3]

#map The return sequence can be passed in multiple sequences for each element of the original sequence called function, but the function also has a corresponding number of parameters

Map (Lambda X,y,z:x+y+z,range (1,3), range (3,5), Range (5,7))

Calculation procedure 1+3+5 = 9 2+4+6=12 results [9,12]

Next we're going to implement

L1 = [1,2,3,4]
Oper = [' + ', '-', ' Leijia ', ' * ']
L2 = [2,44,55,66]

#l1 [0] "oper[0]" l2[0]=? ...



Def plus (x, y):    return  X+ydef Jian (x, y):    return x-ydef Leijia (x, y):    a = 0 for    i in (x, y):        a +=1< C6/>return  adef Chengji (x, y):    return x*ymy_dict = {    ' + ':p LUs,    '-': Jian,    ' Leijia ': Leijia,    ' * ': CHENGJI,}L1 = [1,2,3,4]oper = [' + ', '-', ' Leijia ', ' * ']L2 = [2,44,55,66] #L1 [0] "oper[0]" L2 =? .... res = map (lambda x,y,z:my_dict[y] (x,z), l1,oper,l2) print (list (re

01-python Supplements

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.