Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 and 5 (readfile() and always_popular_names()) are particularly needed for me but any help is fine as well! Restrictions are below the questions. Function

Part 1 and 5 (readfile() and always_popular_names()) are particularly needed for me but any help is fine as well! Restrictions are below the questions.

image text in transcribed

image text in transcribed

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: * * 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? what functions in this project can you call to make read_file much easier to implement? o o 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. Ifrdb has no records for name, return []. Sort multiple years' records (tuples) by year popularity_by_year (rdb, gender, year, top 10): 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 order always_popular_names (rdb, gender, years-None, top-10): 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, use all years present anywhere in the database If top is not provided, default to 10 Hint: call 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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago