subject

Def readFile(filename): dict = {} with open(filename, 'r') as infile: lines = infile. readlines() for index in range(0, len(lines) - 1, 2): if lines[index].strip()=='':continue count = int(lines[index].strip()) name = lines[index + 1].strip() if count in dict. keys(): name_list = dict. get(count) name_list. append(name) name_list. sort() else: dict[count] = [name] print(count, name) return dict def output_keys(dict, filename): with open(filename,'w+') as outfile: for key in sorted(dict. keys()): outfile. write('{}: {}\n'.format(key,'; '.join(dict. get(key print('{}: {}\n'.format(key,';'.join(dict. get(key def output_titles(dict, filename): titles = [] for title in dict. values(): titles. extend(title) with open(filename,'w+') as outfile: for title in sorted(titles): outfile. write('{}\n'.format(title)) print(title) def main(): filename = input('Enter input file name: ') dict = readFile(filename) if dict is None: print('Error: Invalid file name provided: {}'.format(filename)) return print(dict) output_filename_1 ='output_keys. txt' output_filename_2 ='output_titles. txt' output_keys(dict, output_filename_1) output_titles(dict, output_filename_2

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 07:00, MissSmartyPants88
To produce a starlight effect in her photograph, lina should choose the filter for her camera.
Answers: 1
image
Computers and Technology, 23.06.2019 12:30, Prettygirlyaya
How is the brightness of oled of the diaplay is controled
Answers: 1
image
Computers and Technology, 25.06.2019 06:20, joe7977
If you want to change the speed of a layer's horizontal scrolling, what should you change? a. the x coefficient b. the y coefficient c. the virtual width d. the order of the game's layers select the best answer from the choices provided
Answers: 2
image
Computers and Technology, 25.06.2019 08:00, jzjajsbdb8035
Beginning in the 1940s, first-generation computers used circuitsvacuum tube technologylaser technologytransistors
Answers: 2
You know the right answer?
Def readFile(filename): dict = {} with open(filename, 'r') as infile: lines = infile. readlines() fo...

Questions in other subjects:

Konu
Mathematics, 05.09.2019 07:20
Konu
Mathematics, 05.09.2019 07:20