'' ' Requirements: Remove a record from each file into a list, each element of the list ` {' name ':' Egon ',' Sex ':' MALE ',' Age ': 18 is,' the salary ': 3000}' forms ' '' all_user_list = [] with Open ( ' user_info.txt ' , ' R & lt ' , encoding = ' UTF-. 8 ' ) AS F: for per_info in F: per_user_dic = {} name, Sex , Age, the salary = per_info.strip (). Split () per_user_dic [ ' name ']=name per_user_dic['sex' ] = Sex per_user_dic [ ' Age ' ] = int (Age) per_user_dic [ ' the salary ' ] = int (the salary) all_user_list.append (per_user_dic) Print (all_user_list) # 1. Table 1 obtained according to remove most people pay information Print (max (all_user_list, Key = the lambda per_user_dic: per_user_dic [ ' the salary ' ])) # 2. the list 1 was removed youngest person information Print (min (all_user_list, Key = the lambda per_user_dic: per_user_dic [ ' Age ' ])) # The resulting list 1, each of the information mapped to the first name uppercase letter Print (List (Map ( the lambda per_user_dic: {per_user_dic [ ' name ' ] .capitalize (): name, per_user_dic [ ' Sex ' ]: Sex, per_user_dic [ ' Age ' ]: int (Age), per_user_dic [ ' the salary ' ]: int (the salary)}, all_user_list))) # 4. according to Table 1, was filtered off names beginning with a person's information Print (List (filter ( the lambda per_user_dic: per_user_dic [ ' name ' ] .startswith ( ' a ' ), all_user_list)))
# 2. Print recursive Fibonacci number (numbers and the first two to give a third number, such as: 2 0. 1. 1. 4. 3. 7 ...) Item = int (INPUT ( ' entry number >>> : ' )) Start1 = int (INPUT ( ' starting first number >>>: ' )) start2 = int (INPUT ( ' starting second number >>>: ' )) DEF FIB (n-, X , Y): IF n-== 0: return the else : X, Y = Y, X + Y Print (Y) FIB (n- -1 , X, Y) FIB (Item, Start1, start2)
# 3 a nested list of many layers, such as l = [1,2, [3, [4,5,6, [7,8, [9,10, [11,12,13, [14,15 ]]]]]]], taking out all the values recursively l = [1,2, [3, [4,5,6, [7,8, [9,10, [11,12,13, [14 , 15 ]]]]]]] DEF get_element (X): for I in X: IF type (I) == List: get_element (I) the else : Print (I) get_element (L)