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