Question: Create a function that takes a filename as a parameter and returns a list of dictionaries. This function should be generic for any CSV data

Create a function that takes a filename as a parameter and returns a list of dictionaries. This function should be generic for any CSV data set.
Example ('people.csv'):
FirstName,LastName,Birthday,Gender
Susan,Lee,1999-05-26,Female
Lucas,Johnson,2001-12-19,Male
Jose,Ferdinand,2000-01-03,Male
Kay,Muller,1999-11-17,Non-binary
Jade,Wong,2000-08-12,Female
Such files can be read into a program as a list of dictionaries. Using the example above, the code should result inpeoplecontaining the following list:
[{"FirstName": "Susan", "LastName": "Lee", "Birthday": "1999-05-26", "Gender": "Female"},
{"FirstName": "Lucas", "LastName": "Johnson", "Birthday": "2001-12-19", "Gender": "Male"},
{"FirstName": "Jose", "LastName": "Ferdinand", "Birthday": "2000-01-03", "Gender": "Male"},
{"FirstName": "Kay", "LastName": "Muller", "Birthday": "1999-11-17", "Gender": "Non-binary"},
{"FirstName": "Jade", "LastName": "Wong", "Birthday": "2000-08-12", "Gender": "Female"}]
Each index in the list corresponds to a row in the CSV, and each title will specify a column. For example,people[1]["LastName"]would equal"Johnson".
As a reminder, you should not use any modules not covered in class for this assignment. There is a Python module ('csv') that is for reading and writing these types of files, but you will be writing your own function instead.
Your readCsv() function must be generic so that it works regardless of the number of columns or the column header names. It is recommended to copy the example CSV text above and save it in a file as 'people.csv' Download 'people.csv'for testing before moving on to the actual hiring data.
Part 2- Hiring Filter
Implement the following hiring filters (where 'applicants' is the data read in from the CSV file):
filterOverallGpa(applicants, top_n): Sort based on Overall GPA, and return a list with the top N (descending order - i.e. highest GPA in position 0,10th highest GPA in position 9)
filterMajorGpa(applicants, top_n): Sort based on Major GPA, and return a list with the top N (descending order - i.e. highest GPA in position 0,10th highest GPA in position 9)
filterCustomScore(applicants, top_n): Sort based on a custom score (equation below), and return a list with the top N (descending order - i.e. highest score in position 0,10th highest score in position 9)
score =(10* advanced_gpa)+(8* intermediate_gpa)+(6* intro_gpa)+(4* overall_gpa)+(0.25* years_experience)You will need to add this score as a new key-value pair to the dictionary that represents each applicant - the key should be "score" and the value should be the floating point score you calculate
NOTE: careful! As data is read in from a file it will be of type string. Therefore when wanting to make numeric comparisons, do not forget to convert to int or float!
Implement each of these filters by modifying the below Bubble Sort algorithm (note you MUST use bubble sort). You will need to modify this code to work for this lab by comparing the desired field in a dictionary.
# bubble sort sort list in descending order (i.e. largest to smallest)
for i in range(len(a_list)-1):
for j in range(i +1, len(a_list)):
if a_list[j]> a_list[i]:
tmp = a_list[i]
a_list[i]= a_list[j]
a_list[j]= tmp
In your main() function, prompt the user for which filter they want:
Enter '1' to filter based on Overall GPA, '2' to filter based on Major GPA, or '3' to filter based on our Custom Score:
Run the appropriate filter with N=10, then print out the resulting 10 applicants - show First Name Last Name (Gender, Age): Overall GPA, Major GPA, Years of Experience, and Custom Score (only for final filter, rounded to 1 decimal).
Example output (1 line):
Susan Lee (Female,36): Overall GPA =3.7, Major GPA =3.9,8 Years Experience (Score =109.9)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!