day14 (work)
- 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
- The list 1 obtained, the highest-paid extracted person's information
- According to a list obtained by removing most of the young people's information
- According to Table 1, it will get everyone's information in the name mapped to uppercase first letter
- According to a list obtained by filtering out people whose names begin with a message
- Print recursive Fibonacci number (numbers and the first two to give a third number, such as: 0112347 ...)
- 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
1
with open('user_info.txt','w',encoding='utf-8') as fw:
fw.write('''egon male 18 3000
alex male 38 30000
wupeiqi female 28 20000
yuanhao female 28 10000''')
lis=[]
li=['name','sex','age','salary']
with open('user_info.txt','r',encoding='utf-8') as fr:
for i in fr:
info=i.strip().split(' ')
rse=zip(li,info)
dic={k:v for k,v in rse}
lis.append(dic)
print(lis)
2
max1=max(lis,key=lambda di:di['salary'] )
print(max1)
3
min1=min(lis,key=lambda di:di['age'] )
print(min1)
4
map1=map(lambda ma:ma['name'].capitalize(),lis)
map_lis=list(map1)
count=0
for i in lis:
i['name']=map_lis[count]
count+=1
print(lis)
5
filter1=filter(lambda cs:not cs['name'].startswith('A'),lis)
print(list(filter1))
6
def n1(z,x=1,y=0):
print(x)
z-=1
if z==0:
return
x+=y
y=x-y
n1(z,x,y)
n1(20)
7
l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]]]]]]]
def n1(x):
y=x.__iter__()
for i in y:
try:
if len(i)>1:
n1(i)
except Exception:
print(i)
n1(l)