python - Error in the coding : TypeError : list indices must be integer, not str -
code importing file, working perfectly.
but, there problem in line try import csv file, column called 'account key', returning typeerror above.
import file_import fi
function collectively finding data necessary csv file.
def unique_students(csv_file): unique_students_list = set() information in csv_file: unique_students_list.add(csv_file["account_key"]) return len(unique_students_list) #enrollment_num_rows = len(fi.enrollments) #engagement_num_rows = len(fi.daily_engagement) #submission_num_rows = len(fi.project_submissions) #enrollment_num_unique_students = unique_students(fi.enrollments) #engagement_num_unique_students = unique_students(fi.daily_engagement) #submission_num_unique_students = unique_students(fi.project_submissions)
csv_file["account_key"]
lists expect numeric index. far know, dictionaries accept string indices.
i'm not entirely sure supposed do; think logic flawed. bind information
in for
loop, never use it. if list did accept string index, populate set same information on , on since for
loop body remains same same every loop. work if expecting csv_file
custom container type had side effects when indexed (like advancing internal counter).
Comments
Post a Comment