Python built-in functions, anonymous functions, recursive

Source: Internet
Author: User

First, built-in functions

Built-in functions in detail: http://www.runoob.com/python/python-built-in-functions.html

Second, anonymous function

An anonymous function is a specified function that does not need to be displayed

#这段代码def Calc (n):    return N**nprint (calc) #换成匿名函数calc = Lambda n:n**nprint (Calc (10))

  

L=[3,2,100,999,213,1111,31121,333]print (Max (l)) dic={' K1 ': Ten, ' K2 ': +, ' K3 ': 30}print (Max (DIC)) print (Dic[max (DIC, Key=lambda K:dic[k])

  

# 1 file contents are as follows, title: Name, gender, age, salary # # Egon male 3000# Alex male 30000# Wupeiqi female 20000# Yuanhao female 10000with Open (' B.txt ', encoding= ' utf-8 ') as F:    l1=[{' name ': Line.split () [0], ' sex ': Line.split () [1],        ' age ': line.split () [2], ' salary ': Line.split () [3]}for line in F]    # 4 based on the 1 obtained list, the name of each person in the message is mapped to the first capitalization form    l4=[i[' name '] for I in L1]    Print (list (map (lambda item:item.capitalize (), L4))    # 5 Filters out the information about the person whose name starts with a, based on the 1 Get list    l4=[i[' name '] for i in L1 ]    Print (list (filter (lambda name:not name.startswith (' a '), L4)))

  

Third, recursive call

Recursive properties:

1. There must be a clear end condition

2. Each time a deeper level of recursion is reached, the problem size should be reduced compared to the previous recursion

3. Recursive efficiency is not high, too many recursive hierarchy will lead to stack overflow (in the computer, function calls through the stack (stack) This data structure implementation, each time into a function call, the stack will add a stack of frames, whenever the function returns, the stack will reduce the stack frame. Because the size of the stack is not infinite, there are too many recursive calls, which can cause the stack to overflow.

Recursion has two stages

Stage One: Recursion

Phase II: Backtracking

Python built-in functions, anonymous functions, recursion

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.