day 014 jobs

  1. Document reads as follows, titled: name, sex, age, salary
egon male 18 3000
alex male 38 30000
wupeiqi female 28 20000
yuanhao female 28 10000

Requirements:
Remove each record from a file into a list, each element of the list {'name':'egon','sex':'male','age':18,'salary':3000}form

  1. The list 1 obtained, the highest-paid extracted person's information

  2. According to a list obtained by removing most of the young people's information

  3. According to Table 1, it will get everyone's information in the name mapped to uppercase first letter

  4. According to a list obtained by filtering out people whose names begin with a message

    k=['name','sex','age','salary']
    lt1=[]
    with open('test.txt','r',encoding='utf_8') as fr:
        for line in fr:
            line=line.strip()
            line=line.split()
            dic={k:v for k,v in zip(k,line)}
            lt1.append(dic)
    print(lt1)
    print(max(lt1,key=lambda i :i['salary']))
    print(min(lt1,key=lambda i :i['age']))
    print(list(map(lambda i : i['name'].capitalize(),lt1)))
    print(list(filter(lambda i:not i['name'].startswith('a'),lt1)))
  5. Print recursive Fibonacci number (numbers and the first two to give a third number, such as: 0112347 ...)

    def fi(n):
        if n==0:
            return 0
        if n==1 or n==2:
            return 1
        return fi(n-1)+fi(n-2)
    n=int(input())
    for i in range(0,n+1):
        print(fi(i))
  6. A list of many layers of nested, such as l = [1,2, [3, [4,5,6, [7,8, [9,10, [11,12,13, [14,15]]] ]]]], remove all the values ​​recursively

def f1(l):
    if len(l)==0:
        return
    if type(l[0])==list:
        f1(l[0])
    else:
        print(l[0])
        del l[0]
        f1(l)

f1(l)

Guess you like

Origin www.cnblogs.com/zqfzqf/p/11586911.html