Python path--DAY13---Functions--ternary expressions, recursion, anonymous functions, built-in functions-----exercises

Source: Internet
Author: User

1, the file content is as follows, the title is: Name, sex, age, salary

Egon Male 18 3000
Alex Male 38 30000
Wupeiqi Female 28 20000
Yuanhao Female 28 10000

Requirements:
Remove each record from the file into the list,
Each element of the list is {' name ': ' Egon ', ' sex ': ' Male ', ' age ': the form of ' salary ': 3000}

2 based on the list obtained by 1, take out the information of the person with the highest salary
3 According to 1 get the list, take out the information of the youngest person
4 based on the list obtained in 1, the name in each person's information is mapped to the first letter capitalized form
5 according to the 1 obtained list, filter out the information of the person whose name begins with a
6 use recursion to print the Fibonacci sequence (the first two numbers and get a third number, such as: 0 1 1 2 3 4 7 ...)

71 nested Many layers of a list, such as l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]] []]], and recursively take out all the values

1data = []2With open ('Ceshi.txt','R', encoding='Utf-8') as F:3      forLineinchF:4I= Line.strip ('\ n'). Split (' ')5DIC = {6             'name': i[0],7             'Sex': i[1],8             ' Age': Int (i[2]),9             'Salary': Int (i[3])Ten         } One data.append (DIC) A  - #[{' Name ': ' Egon ', ' sex ': ' Male ', ' age ': ' Salary ' : - #{' name ': ' Alex ', ' sex ': ' Male ', ' age ': $, ' salary ': 30000}, \ the #{' name ': ' Wupeiqi ', ' sex ': ' Female ', ' age ': +, ' salary ': 20000},\ - #{' name ': ' Yuanhao ', ' sex ': ' Female ', ' age ': +, ' salary ': 10000}] -  -Res=max (data,key=Lambdax:x['Salary']) +Res1=min (data,key=Lambdax:x[' Age']) -  +Res2=map (LambdaX: {'name': x['name'].capitalize (), A             'Sex': x['Sex'], at             ' Age': x[' Age'], -             'Salary': x['Salary']}, - data) -  -  -Res3 = Filter (LambdaX: notx['name'].startswith ('a'), data) in  -  to #Non-recursive + deffib (n): -a,b=0,1 the      whileA <N: *         Print(a,end=' ') $a,b=b,a+bPanax Notoginseng     Print() -  theFIB (10) + #Recursive A deffib (a,b,stop): the     ifA >Stop: +         return -     Print(a,end=' ') $FIB (b,a+b,stop) $  -FIB (0,1,10)
l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]] []def  list1 (x):    for inch x:         if   not type (item) = = List            :print(item        )else:           List1 (item)

Python path--DAY13---Functions--ternary expressions, recursion, anonymous functions, built-in functions-----exercises

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.