• Day 14 作业


    info_list = []
    
    with open('info.txt', 'r', encoding='utf8') as fr:
        for info in fr:
            info_dict = {}
            name, sex, age, salary = info.strip().split()
    
            info_dict['name'] = name
            info_dict['sex'] = sex
            info_dict['age'] = int(age)
            info_dict['salary'] = int(salary)
            # print(info_dict)
            info_list.append(info_dict)
    print(info_list)
    
    # 根据1得到的列表,取出薪资最高的人的信息
    print(max(info_list, key=lambda dic: dic['salary']))
    
    # 根据1得到的列表,取出最年轻的人的信息
    print(min(info_list, key=lambda dic: dic['age']))
    
    # 根据1得到的列表,将每个人的信息中的名字映射成首字母大写的形式
    res = map(lambda dic: dic['name'].capitalize(), info_list)
    print(list(res))
    
    # 根据1得到的列表,过滤掉名字以a开头的人的信息
    res = filter(lambda dic: dic['name'][0] != 'a', info_list)
    print(list(res))
    
    # 使用递归打印斐波那契数列(前两个数的和得到第三个数,如:0 1 1 2 3 4 7...)
    n1 = 0
    n2 = 1
    count = 0
    def a(x):
        global count
        global n1
        global n2
        if x == 1:
            print(n1)
        elif x == 2:
            print(n1, n2)
        else:
            while count < x:
                nsum = n1 + n2
                print(nsum, end=',')
                n1 = n2
                n2 = nsum
                count += 1
                a(x)
    
    a(10)
    
    # 一个嵌套很多层的列表,如l=[1,2,[3,[4,5,6,[7,8,[9,10,[11,12,13,[14,15]]]]]]],用递归取出所有的值
    
    # x = 0
    l = [1,2,[3,[4,6,[7,8,[9,10,[11],[12,[13,14],[15]]]]]]]
    # n = len(l)
    # def lis(l):
    #     # global x
    #     print(l[0])
    #
    #     l.remove(l[0])
    #     if type(l[0]) == list:
    #         l = l[0]
    #     # l = l[0]
    #
    #     lis(l)
    
    # lis(l)
    
    def lis(l):
        for i in l:
            if type(i) == list:
                lis(i)
            else:
                print(i)
    
    lis(l)
    
  • 相关阅读:
    服务端获取实际IP工具类
    vue-element-admin整合服务端代理api
    elemengui分页
    vue获取浏览器地址栏参数
    el-table-column动态判断显示性别男女
    nginx代理静态页面添加二级目录
    nginx配置代理指向Redis
    SpringBoot整合Redis日志反复提示Redis重连问题
    centos7安装Redis
    nohup启动jar包
  • 原文地址:https://www.cnblogs.com/2222bai/p/11587374.html
Copyright © 2020-2023  润新知