Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.6 PROBLEMS: Functions dealing with ranked databases popularity_by_year(rdb, gender, year, top=10): accepts a ranked database rdb, gender, year, and top. It finds for the

Python 3.6

image text in transcribed

image text in transcribed

PROBLEMS:

Functions dealing with ranked databases

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! Functions creating/updating ranked databases These functions start from a database that either has incomplete rankings, or with incorrect rankings. They will need to create correct rankings for the rsulting database.

Functions creating/updating ranked databases

These functions start from a database that either has incomplete rankings, or with incorrect rankings. They will need 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 each 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:10, B:5, C:5, D:5, 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 returns None.

rank_names (db): This function accepts an existing database and ranks all names for all years of data present, making the database become ranked.

This function should return None.

Rank male and female names separately.

Hint: use previous functions!

image text in transcribed

DATA FILES:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago