day 14作业

dict = {'name': '', 'sex': '', 'age': '', 'salary': ''}
lists = []
with open('test.txt', 'r+', encoding='utf8') as fr:
for i in fr:
liv = i.strip().split(' ')
# print(liv)
res = {k: v for k, v in zip(dict, liv)}
# print(res)
lists.append(res)
# print(res.next())
print(lists)

薪资最高

res = max(lists, key=lambda name: name['salary'])
print(res)

最年轻

yong = min(lists, key=lambda age: age['age'])
print(yong)

大写名字第一个字母

for i in range(len(lists)):

lists[i]['name'] = lists[i]['name'].title()

print(lists)

res = map(lambda f: f['name'].title(), lists)
lists1 = list(res)
print(lists1)

删除a开头的人的信息

for i in range(len(lists)-1):

if lists[i]['name'][0] == 'a':

del lists[i]

print(lists)

res = filter(lambda f: not f['name'].startswith('a'), lists)

lists2 = list(res)

print(lists2)

a = 0
b = 1
count = 0

while count <5:

print(a, b)

a += b

b += a

count +=1

菲波拉切数列

def fb():

global a

global b

global count

count += 1

print(a, b,end=' ')

a += b

b += a

if count == 10:

return

return fb()

fb()

posted @ 2019-09-26 01:01  LZF_GD  阅读(72)  评论(0编辑  收藏  举报
Live2D