Question: Explain what the following Python program is used for and how it works? filename = raw_input(Please enter your input filename: ) f = open(filename) csv_f

Explain what the following Python program is used for and how it works?

filename = raw_input("Please enter your input filename: ")

f = open(filename)

csv_f = csv.reader(f)

link_fre = dict()

nameList = row[2].split(', ')

nameList.sort()

combination_names = itertools.combinations(nameList, 2)

for combination in combination_names:

if combination in link_fre:

link_fre[combination] += 1

else:

link_fre[combination] = 1

new_f = open('network.csv', 'wt')

try:

writer = csv.writer(new_f)

writer.writerow( ('source', 'target', 'weight') )

for key in link_fre:

writer.writerow( (key[0], key[1], link_fre[key]) )

finally:

new_f.close()

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!