Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python only please! For each of these functions you have to create a function that satisfies the criteria that is listed below each on using

Python only please! For each of these functions you have to create a function that satisfies the criteria that is listed below each on using only range, len, int, open, close, readlines, .get(), .items(), .remove(), .append(), .split(), and .sort(). Please help.

image text in transcribed

Function dealing with File Reading This is the only fiunction that deals with file reading; you can attempt it separately from all the other functions, because the other functions accept database dictionaries, and not file names they don't rely upon this function's output at all. If this function is taking up significant time please use your time wisely and keep working through the other required functions to maximize your time spent and score carned. .read file(filename): This will accept the file name as a string, and assumes i is a CSV file as described above (with our name data in the same format as the example, but with any number of rows after the header row). It will open the file, read all the name entries, and correctly create the unranked database Return the resulting unranked database Set all rankings to None You can assume that for any given name/gender, there will be at most one entry for each year Sort al [(year.count,rank)] lists by year Hints: How can you break this task down into multiple phases, cach one taking a pass over the data and making something slightly more useful towards getting the result? o o what functions in this project can you call to make read file much casier to implement? Functions dealing with ranked databases These functions rely upon rankings. You can assume the incoming database is always correctly ranked. get_rank_for_name year (rdb, name, gender, year): accepts a ranked database rdb, name, gender and year. It finds and returns the rank of that name/gender in the specified year. It returns None if there is no relevant record in the database popularity_by_nama(rdb, name, gender): accepts a ranked databasc rdb, name, and gender. It finds the ranks for all years included in rdb for name, assemble them in a list of pairs [ (year,rank)], and retum the list. If rdb has no records for name, return []. Sort multiple years' records (tuples) by year. popularity_by_year (rdb, gender, year, top 1e): accepts a ranked database rdb, gender, year, and top. It finds for the specified year, the top popular names and returns them in a list of pairs (rank,name)] Sort the list of pairs. You can assume top is always a positive integer. If top is not provided, use default value and report the top 10 popular names. If top is larger than the number of stored names for that year, report all names in the right ordeir always_popular_names (rdb, gender, years None, top 1): accepts a ranked database rdb, gender a list of years and a top threshold. It searches in the database for (name, gender) records that for all indicated years are present and always ranked within (and including) top, and return them as a list of names. alphabetically sorted. Their rankings across the years are not part of the returned answer If years is not provided, usc all ycars present anywhere in the databasc If top is not provided, default to 10 Hint: call previous functions! Functions creating/updating ranked database:s These functions start from a database that either has incomplete rankings, or with incorrect rankings. They will to create correct rankings for the rsulting database rank_names_by_year_gender (db, year, gender) This function accepts an existing (unranked) database db, a year and a gender. It calculates the ranking of names according to their counts and updates that information into the database. Rank male and female names separately. The most popular name for cach gender (with the highest count) gets a rank value of 1 . Assign all tied-count names with the same rank and make sure the next rank is adjusted accordingly Given counts of A:1e, B:5, Ci5, Di5, E:1, they'd get rankings of A-1, B-2, c-2, D-2, E-5 This function updates the database in-place and retuns None rank_names (db) This function accepts an existing databasc and ranks all names for all ycars of data present, making the database become ranked. This function should return None Rank male and female names separately . Hint: use previous functions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago