zoukankan      html  css  js  c++  java
  • s5_day11作业

    # 1 文件内容如下,标题为:姓名,性别,年纪,薪资
    #
    # egon male 18 3000
    # alex male 38 30000
    # wupeiqi female 28 20000
    # yuanhao female 28 10000
    #
    # 要求:
    # 1 从文件中取出每一条记录放入列表中,
    # 列表的每个元素都是{'name':'egon','sex':'male','age':18,'salary':3000}的形式
    # 第一种
    # l=[]
    # with open('1',encoding='utf-8')as f:
    #     for line in f:
    #         l1=line.split()
    #         l.append({'name':l1[0],'sex':l1[1],'age':l1[2],'salary':l1[3]})
    # print(l)
    # 第二种列表解析
    # with open('1',encoding='utf-8')as f:
    #     l=[{'name':line.split()[0],'sex':line.split()[1],'age':line.split()[2],'salary':line.split()[3]} for line in f]
    # print(l)
    # 2 根据1得到的列表,取出薪资最高的人的信息
    # with open('1',encoding='utf-8')as f:
    #     l=[{'name':line.split()[0],'sex':line.split()[1],'age':line.split()[2],'salary':line.split()[3]} for line in f]
    # print(max(l,key=lambda x:x['salary']))
    # print([i for i in list if i['salary'] == max(i['salary'] for i in list)])
    # 3 根据1到的列表,取出最年轻的人的信息
    # with open('1',encoding='utf-8')as f:
    #     l=[{'name':line.split()[0],'sex':line.split()[1],'age':line.split()[2],'salary':line.split()[3]} for line in f]
    # print(min(l,key=lambda x:x['age']))
    # print([i for i in list if i['age']==min(i['age'] for i in list)])
    # 4 根据1得到的列表,将每个人的信息中的名字映射成首字母大写的形式
    # with open('1',encoding='utf-8')as f:
        # l=[{'name':line.split()[0],'sex':line.split()[1],'age':line.split()[2],'salary':line.split()[3]} for line in f]
        # print(list(map(lambda x:x['name'].capitalize(),l)))
        # print([i['name'].capitalize() for i in l])
        # print(list(map(lambda x:x['name'].title(),l)))
    # 5 根据1得到的列表,过滤掉名字以a开头的人的信息
    # with open ('1',encoding='utf-8') as f:
    #     list=([{'name':line.split()[0],'sex':line.split()[1],'age':int(line.split()[2]),'salary':int(line.split()[3]),} for line in f])
        # print([i for i in list if i['name'].startswith('a')])
        # print(next(filter(lambda x:x['name'].startswith('a'),list)))
    # 6 使用递归打印斐波那契数列(前两个数的和得到第三个数)
    #     0 1 1 2 3 4 7...
    # def recur_fibo(n):
    #    if n <= 1:
    #        return n
    #    else:
    #        return(recur_fibo(n-1) + recur_fibo(n-2))
    # nterms = int(input("您要输出几项? "))
    # # 检查输入的数字是否正确
    # if nterms <= 0:
    #    print("输入正数")
    # else:
    #    for i in range(nterms):
    #        print(recur_fibo(i),end=' ')
  • 相关阅读:
    vim复制
    嵌入式Linux学习(二)
    (Java实现) 洛谷 P1042 乒乓球
    (Java实现) 洛谷 P1042 乒乓球
    (Java实现) 洛谷 P1071 潜伏者
    (Java实现) 洛谷 P1071 潜伏者
    (Java实现) 洛谷 P1025 数的划分
    (Java实现)洛谷 P1093 奖学金
    (Java实现)洛谷 P1093 奖学金
    Java实现 洛谷 P1064 金明的预算方案
  • 原文地址:https://www.cnblogs.com/z-x-y/p/7085672.html
Copyright © 2011-2022 走看看