2019.9.25 작업

1796 단어
#  
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)

좋은 웹페이지 즐겨찾기