Page 25 for

  1. Document reads as follows, titled: 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 a file into a list, each element of the list {'name':'egon','sex':'male','age':18,'salary':3000}form

data = '''egon male 18 3000
alex male 38 30000
wupeiqi female 28 20000
yuanhao female 28 10000
'''
with open('user_info.txt','w',encoding='utf-8') as fw:
    fw.write(data)
    fw.flush()

lt = []
li = ['name','sex','age','salary']
with open('user_info.txt','r',encoding='utf-8') as fr:
    for i in fr:
        lis = i.strip().split() #切割 --》列表
        # print(i)
        res = zip(li,lis) #存储
        dic = {k:v for k,v in res}
        lt.append(dic)
print(lt)
  1. The list 1 obtained, the highest-paid extracted person's information
res1 = max(lt,key=lambda k:k["salary"])
print(res1)
    
  1. According to a list obtained by removing most of the young people's information
res2 = min(lt,key=lambda k1:k1['age'])
print(res2)
  1. According to Table 1, it will get everyone's information in the name mapped to uppercase first letter
res3=map(lambda ma:ma['name'].title(),lt)
map_lis=list(res3)
count = 0
for i in lt:
    i['name']=map_lis[count]
    count+=1
print(lt)
  1. According to a list obtained by filtering out people whose names begin with a message
filter_res = filter(lambda vb:not vb['name'].startswith('a'),lt)
print(list(filter_res))
  1. Print recursive Fibonacci number (numbers and the first two to give a third number, such as: 0112347 ...)
def fib(n):
 """输出斐波那契数列"""
 if n <= 1:
     return n
 else:
     return(fib(n-1) + fib(n-2))
fib(n)
  1. A list of many layers of nested, such as l = [1,2, [3, [4,5,6, [7,8, [9,10, [11,12,13, [14,15]]] ]]]], remove all the values ​​recursively

Guess you like

Origin www.cnblogs.com/shaozheng/p/11587070.html