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 peoplecsv:
FirstName,LastName,Birthday,Gender
Susan,Lee,Female
Lucas,Johnson,Male
Jose,Ferdinand,Male
Kay,Muller,Nonbinary
Jade,Wong,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": "Gender": "Female"
FirstName: "Lucas", "LastName": "Johnson", "Birthday": "Gender": "Male"
FirstName: "Jose", "LastName": "Ferdinand", "Birthday": "Gender": "Male"
FirstName: "Kay", "LastName": "Muller", "Birthday": "Gender": "Nonbinary"
FirstName: "Jade", "LastName": "Wong", "Birthday": "Gender": "Female"
Each index in the list corresponds to a row in the CSV and each title will specify a column. For example,peopleLastNamewould equalJohnson
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 Hiring Filter
Implement the following hiring filters where 'applicants' is the data read in from the CSV file:
filterOverallGpaapplicants topn: Sort based on Overall GPA, and return a list with the top N descending order ie highest GPA in position th highest GPA in position
filterMajorGpaapplicants topn: Sort based on Major GPA, and return a list with the top N descending order ie highest GPA in position th highest GPA in position
filterCustomScoreapplicants topn: Sort based on a custom score equation below and return a list with the top N descending order ie highest score in position th highest score in position
score advancedgpa intermediategpa introgpa overallgpa yearsexperienceYou will need to add this score as a new keyvalue 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 ie largest to smallest
for i in rangelenalist:
for j in rangei lenalist:
if alistj alisti:
tmp alisti
alisti alistj
alistj tmp
In your main function, prompt the user for which filter they want:
Enter to filter based on Overall GPA, to filter based on Major GPA, or to filter based on our Custom Score:
Run the appropriate filter with N then print out the resulting applicants show First Name Last Name Gender Age: Overall GPA, Major GPA, Years of Experience, and Custom Score only for final filter, rounded to decimal
Example output line:
Susan Lee Female: Overall GPA Major GPA Years Experience Score
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
