Question: Python help read_file(fp) will have the file pointer fp passed into it. The first line of the file contains the value for the variable n,

Python help read_file(fp) will have the file pointer fp passed into it. The first line of the file contains the value for the variable n, the number of users in the social network. We have provided the code to read n and initialize a list network containing n nested empty lists (e.g., n = 3 would correlate to creating the list [ [], [], [] ]). This list of lists will be used to hold the list of friends for each of the n users. You can then use a for loop to iterate over the remaining lines of the file. For each line of the file you will want to obtain the two user id values on that linewe denote those user ids as u and v. You need to place v into us list and also place u into vs list, since they are mutual friends (hint: use the list append() method to place each user id into a list). Finally you will return network, which is the list of lists that was created. def read_file(fp): ''' Remember the docstring''' # Read n and initizlize the network to have n empty lists -- # one empty list for each member of the network n = fp.readline() n = int(n) network = [] for i in range(n): network.append([]) # You need to write the code to fill in the network as you read the file # Hint: append appropriate values to the appropriate lists. # Each iteration of the loop will have two appends -- why? return network 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!