Essential notes4.py - #problem1_Boozy Containers header

Essential notes4.py - #problem1_Boozy Containers header

This preview shows page 1 - 2 out of 4 pages.

##problem1_Boozy Containers header = ['school', 'sex', 'age', 'address', 'famsize', 'Pstatus', 'Medu', 'Fedu', 'Mjob', 'Fjob', 'reason', 'guardian', 'traveltime', 'studytime', 'failures', 'schoolsup', 'famsup', 'paid', 'activities', 'nursery', 'higher', 'internet', 'romantic', 'famrel', 'freetime', 'goout', 'Dalc', 'Walc', 'health', 'absences', 'G1', 'G2', 'G3'] data_rows = [['GP', 'F', '18', 'U', 'GT3', 'A', '4', '4', 'at_home', 'teacher', 'course', 'mother', '2', '2', '0', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'no', 'no', '4', '3', '4', '1', '1', '3', '6', '5', '6', '6'], ['GP', 'F', '17', 'U', 'GT3', 'T', '1', '1', 'at_home', 'other', 'course', 'father', '1', '2', '0', 'no', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'no', '5', '3', '3', '1', '1', '3', '4', '5', '5', '6'], ['GP', 'F', '15', 'U', 'LE3', 'T', '1', '1', 'at_home', 'other', 'other', 'mother', '1', '2', '3', 'yes', 'no', 'yes', 'no', 'yes', 'yes', 'yes', 'no', '4', '3', '2', '2', '3', '3', '10', '7', '8', '10'], ['GP', 'F', '15', 'U', 'GT3', 'T', '4', '2', 'health', 'services', 'home', 'mother', '1', '3', '0', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', '3', '2', '2', '1', '1', '5', '2', '15', '14', '15'],['GP', 'F', '16', 'U', 'GT3', 'T', '3', '3', 'other', 'other', 'home', 'father', '1', '2', '0', 'no', 'yes', 'yes', 'no', 'yes', 'yes', 'no', 'no', '4', '3', '2', '1', '2', '5', '4', '6', '10', '10']] """ 001 通过 List header 信息,寻找另一个 list 的指定行对应的内容 """ def lookup_value(col_name, row_id, header, data_rows): col_id = header.index(col_name) # "age" --> 2 return data_rows[row_id][col_id] # 18 #lookup_value('age', 0, header, data_rows) == '18' #lookup_value('G2', 3, header, data_rows) == '14' """ 002 通过 List header 信息,寻找另一个 list 的对应列的全部内容 """ def lookup_column_values(col, header, data_rows): col_id = header.index(col) # 得到 index return [row[col_id] for row in data_rows] # 遍历每一行 #values = lookup_column_values('age', header, data_rows) #assert values[:5] == ['18', '17', '15', '15', '16'] """ 003 通过 List header 信息,寻找另一个 list 的对应列的唯一值 unique value """ def get_unique_values(col, header, data_rows): return list(set(lookup_column_values(col, header, data_rows))) #solution2
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '19
  • susan lee

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture