Question
Python 3.6 PROBLEM STATEMENTS: Functions dealing with unranked databases: add_name (db, name, gender, year, count, rank=None): This function accepts an existing database db, name, gender,
Python 3.6
PROBLEM STATEMENTS:
Functions dealing with unranked databases:
add_name (db, name, gender, year, count, rank=None): This function accepts an existing database db, name, gender, year, count, and rank then it updates the database to include that information.
Return None.
The resulting database is considered unranked, as the addition means the rankings aren't up-to-date. It's acceptable that there are some None ranks and some numeric ranks, so some calls to add_name may intentionally use None as the rank argument.
If there is already an entry for that name/gender/year, you must replace it.
Hint: This function can be helpful to implement read_file(), as well as any functions that must create a new database dictionary.
Function dealing with File Reading
This is the only function 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 earned.
read_file(filename): This will accept the file name as a string, and assumes it 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 all [(year,count,rank)] lists by year.
Hints:
o How can you break this task down into multiple phases, each one taking a pass over the data and making something slightly more useful towards getting the result?
o what functions in this project can you call to make read_file much easier 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_name(rdb, name, gender): accepts a ranked database 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 return the list. If rdb has no records for name, return []. Sort multiple years records (tuples) by year.
DATA FILES:
Test cases : https://repl.it/N7up/1
Thank you!
Restrictions no modules may be imported. (this definitely includes the csv module - do the work directly!) Allowed * all basic expressions and statements file reading: open(), close(), read(), readline), readlines (), with syntax dictionaries: len, get, clear, copy, keys, values, items, pop, popitem, update all sets and set operations; all exception handling blocks/raises. functions: len(), range(), min), max), enumerate(), int), and any functions you write list methods: remove(), insert(), append(), extend), pop(), index() string methods: split), endswith), startswith), join(), insert, index) more: sorted(), sort(), reversed(), reverse() calling other functions of the project (and your own defined helper functions). Please do this! ) Hint In our solution, we only used range, len, int, open, close, readlines, .get(), .items, .remove)., .append), .split(), .sort()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started