• 2019.9.25作业


    # 前戏
    info_lt = []
    att_lt = ['name', 'sex', 'age', 'salary']
    with open('info.txt', 'r', encoding='utf8') as fr:
        for info in fr:
            info = info.strip().split(' ')
            # eve = {k:v for k in att_lt for v in info }
            eve = dict(zip(att_lt, info))
            info_lt.append(eve)
        print(info_lt)
    
    
    # 1薪资最高
    def max_salary():
        sa_lt = []
        for i in range(len(info_lt)):
            sal = info_lt[i]['salary']
            sa_lt.append(sal)
        max_sal = max(sa_lt)
        print(max_sal)
    
    
    max_salary()
    
    
    # 2年纪最低
    def min_age():
        age_lt = []
        for i in range(len(info_lt)):
            ag = info_lt[i]['age']
            age_lt.append(ag)
        min_ag = min(age_lt)
        print(min_ag)
    
    
    min_age()
    
    
    # 3名字首字母大写
    def cap():
        nam_lt = []
        for i in range(len(info_lt)):
            nam = info_lt[i]['name']
            nam_lt.append(nam)
        name_lt = list(map(lambda i: i.capitalize(), nam_lt))
        print(name_lt)
    
    
    cap()
    
    
    # 4 过滤a开头
    def beginwitha():
        nam_lt = []
        for i in range(len(info_lt)):
            nam = info_lt[i]['name']
            nam_lt.append(nam)
        name_lt = list(filter(lambda i: not i.startswith('a'), nam_lt))
        print(name_lt)
    
    
    beginwitha()
    
    
    # 5 斐波那契
    def fib(x):
        if x <= 2:
            return 1
    
        return fib(x - 2) + fib(x - 1)
    
    
    for i in range(1, 5):
        print(fib(i))
    
    # 6 递归取值
    lt = [1, 2, [3, [4, 5, 6, [7, 8, [9, 10, [11, 12, 13, [14, 15]]]]]]]
    
    
    def get_lst(lt):
        if not type(lt[len(lt) - 1]) == list:
            for i in range(len(lt)):
                print(lt[i])
            return
        for i in range(len(lt)):
            if not i == len(lt) - 1:
                print(lt[i])
            if i == (len(lt) - 1):
                lt = lt[-1]
                return get_lst(lt)
    
    
    get_lst(lt)
    
    
  • 相关阅读:
    rabbitmq 学习
    linux下安装rabbitmq 集群
    excel中将时间戳转换为日期格式
    python实现批量修改服务器密码
    python 根据字典的键值进行排序
    python字符串的拼接
    python的变量
    python基础1
    【性能分析】使用Intel VTune Amplifier
    【vim】搜索与替换
  • 原文地址:https://www.cnblogs.com/agsol/p/11587597.html
Copyright © 2020-2023  润新知