Exercise questions _ recursive and built-in functions

  1. The content of the file is as follows, the title is: name, gender, age, salary
egon male 18 3000alex male 38 30000wupeiqi female 28 20000yuanhao female 28 10000

Requirement:
Take out each record from the file and put it into the list. Each element of the list is {'name':'egon','sex':' male','age':18,'salary':3000}

2, according to the list obtained in 1, take out the information of the person with the highest salary

3. According to the list obtained by 1, take out the information of the youngest person

4. According to the list obtained by 1, map the name of each person’s information to the form of initial capital letters

< p>5. Filter out the information of people whose names start with a according to the list obtained by 1.

6. Print the Fibonacci sequence using recursion (the sum of the first two numbers gets the third number, Such as: 0 1 1 2 3 5 8…)

7. A list with many levels of nesting, such as l=[1,2,[3,[4,5,6,[7 ,8,[9,10,[11,12,13,[14,15]]]]]]], use recursion to retrieve all values

import copylist1 = [' name','sex','age','salary']list2 = []with open('num_info.txt','r',encoding='utf8') as fr: list0 = fr.read().split ('
') # print(list0) for i in list0: u_info = i.split('') dic = {k:v for k,v in zip(list1,u_info)} list2.append(dic)# 1. Get a list of dictionaries print(list2) # 2. print(max(list2,key=lambda dic:dic['salary']))# 3. print(min(list2,key=lambda dic:dic[ 'age']))# 4. list3 = copy.deepcopy(list2)for i in list3: i['name'] = i['name'].capitalize()print(list3)res = map(lambda item:item['name'].capitalize(),list3)print(list(res) )5, res2 = filter(lambda item:item['name'].startswith('a'), list2)print(list(res2))
# 6, def func (a,b,n): if b> n: return print(a,end='') func(b,a+b,n)func(0,1,50)
# 7l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]]]]]]]]def fun(lis): for i in lis: if type(i) is list: fun(i) else: print(i,end='')get(l)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5301 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.