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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:30
In the film "epic 2015," epic is the name for:
Answers: 3
question
Computers and Technology, 22.06.2019 09:50
17. implement the jvm dload instruction for the mic-2. it has a 1-byte index and pushes the local variable at this position onto the stack. then it pushes the next higher word onto the stack as well
Answers: 2
question
Computers and Technology, 22.06.2019 13:30
In which phase does software coding and testing happen in the spiral model? the spiral model does not have a separate testing phase. both, software coding and testing occurs during the phase.
Answers: 3
question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
You know the right answer?
Def readFile(filename): dict = {} with open(filename, 'r') as infile: lines = infile. readlines() fo...
Questions
question
History, 13.04.2021 19:20
question
Mathematics, 13.04.2021 19:20
question
Mathematics, 13.04.2021 19:20
Questions on the website: 13722360