with open(r'C:UsersliukaDesktop我的项目homework.text','r',encoding='utf8') as fr:
lt1 = []
lt2 = ['name', 'sex', 'age', 'salary']
lt3 = []
for i in fr:
data=list(i.strip().split())
print(data)
data[3] = int(data[3])
data[2] = int(data[2])
dic = {k:v for k,v in zip(lt2,data)}
lt1.append(dic)
print(lt1)
for i in lt1:
num = i.get('salary')
lt3.append(num)
def fun(item):
return item['salary']
# max_num = max(lt1,key=fun)
max_num = max(lt1,key=lambda sfjsaldjfdjsofo:sfjsaldjfdjsofo['salary'])
print(max_num)
min_age=min(lt1,key=lambda item:item['age'])
print(min_age)
def fun(item):
item['name']=item['name'].capitalize()
return item['name']
yinshe = map(fun,lt1)
print(list(yinshe))
filter_start_name_a = filter(lambda item:not (item['name'].startswith('a') or item['name'].startswith('A')) ,lt1)
print(list(filter_start_name_a))
def sum_num(a,b,stop):
if a >stop:
return
print(a)
sum_num(b,a+b,stop)
sum_num(0,1,10)
l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]]]]]]]
def quzhi(l):
for i in l:
if type(i) is list:
quzhi(i)
else:
print(i)
quzhi(l)