logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

You will develop a Python program that takes two files and extracts some information.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

File Specifications

You will develop a Python program that takes two files and extracts some information. The first file (Names.txt) has the full name of a person in each line. The full names are unique. Assume the line numbers start from zero. The number of the line is the index of the person. In the second file (Friends.csv) at each corresponding line to the first file, there are the indices of the friends.

Names_small.txt (shorter version of the Names.txt)

Gregory Williams

Mark Mercado

Devin Baldwin

Samantha Murray

→ name at index 0

→ name at index 1

Brandon Garcia

Laura Todd

Alexander Rogers

Michael Walter Elizabeth Russell

Janet Myers

Friends small.csv (shorter version of the Friends.csv)

2,5,4,8,

0,6,7,6, 2, 3, 9,0,7,3,1, 8,5,7,8, 0,5,7,2,3,

4, 6, 8,0,

7,9,8,2,5,4,

1,6,

0, 3, 6, 4,

0,1,8,2,

→ friend data for name at index 0

→ friend data for name at index 1

Assignment Specifications

You will develop a Python program that has the following functions

open_file (s) file pointer:

a. This function prompts the user to input a file name to open and keeps prompting until a correct name is entered. The parameter, s, is a string to incorporate into your prompt so you are prompting the user for a particular type of file ("names", "friends"). b. Parameters: string

c. Returns: a file pointer

d. Display: prompts and error messages

read_names (fp) list of strings

a. This function reads the Names.txt file using file pointer, fp. The file has no header. There is one name per line-remember to strip off the carriage return. Because order matters you must create the list with the names in the same order that they appear in the file (which basically means simply read it in order). The names are unique (which doesn't matter at first but makes your life easier later when you build a dictionary).

Return the list of names (strings).

b. Parameter: file pointer

c. Returns: list of strings

d. Displays: nothing

read_friends (fp, names_lst) → list of lists of strings

a. This function reads the Friends.csv file using file pointer, fp. The file has no header. As shown above (File specification section), each line is a list of indices (ints) of names. That is, line 0, the first line of the file corresponds to the name at index 0 of names_1st, and so on.

However, when you build the list of friends for each name, create a list of names (strings), not a list of indices (but you can create a list of indices first, if you wish, and then convert them to names later). Use the ints in the file to index into names_1st to get the corresponding name.

Return the list of list of names (strings).

b. Parameter: file pointer, list of strings

C. Returns: list of lists of strings

d. Displays: nothing

create_friends_dict (names_lst, friends_1st) → dict

a. This function takes the two lists created in the read_names function and the read_friends function and builds a dictionary. Build a dictionary with name as the key and a list of friends as the value. You can use the fact that the names_1st has no repeated names to make this task easier. The lists are parallel in the sense that the friends at index X of the friends_1st corresponds to the name at index X of the names_lst. (For those looking for an extra challenge you can do this function in one line using the Python zip function.)

b. Parameter: list of strings, list of lists of strings

c. Returns: dictionary (key is a string; value is a list of strings) d. Displays: nothing

find_common_friends (namel, name2, friends_dict)

a.

set

This function takes two names (strings) and the friends_dict (returned by the create_friends_dict) and returns a set of friends that the two names have in common. The names namel and name 2 should not be in the set of friends returned. This function is easiest done using Python set operations. Hint: a list can be converted to a set by using the set () function, e.g. set (list). Once you have friends in sets you can use set operations to get the desired set to return. b. Parameter: string, string, dictionary C. Returns: set of strings

d. Displays: nothing

find_max_friends (names_lst, friends_1st) list of strings, int a. This function takes a list of names and the corresponding list of friends and determines who has the most friends. It returns a list of those with the most friends and how many friends they have. Sort the list of names alphabetically (makes testing consistent). Hint: one approach is to start by building a list of the number of friends that each person has. You can find the max () of that list. Then go through that list of the number of

friends and find the indices of those who have max () number of friends. (List

comprehension is useful here, but not necessary.)

b. Parameter: list of strings, list of list of strings

c. Returns: list of strings, int

d. Displays: nothing

find_max_common_friends (friends_dict)

list of tuples, int

a. This function takes the friends dictionary and finds which pairs of people have the most friends in common. It returns a list of those pairs with the most common friends and how many friends they have. Each pair is represented as a tuple of names (strings). Sort the list of tuples alphabetically (makes testing consistent).

Note three constraints:

I. Each pair of people is represented only once. That is, pair (A,B) has a symmetric pair (B,A) which has the same people. Use the pair (A,B) where A

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

959 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

950 Answers

Hire Me
expert
AyooluwaEducation

873 Answers

Hire Me
expert
RIZWANAMathematics

643 Answers

Hire Me

Get Free Quote!

325 Experts Online