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 19:30
Once the data center routes to the destination server that hosts the website, what's the next step in the internet process? user’s browser renders html code from destination server into web page request goes through router/model and isp request routed to nameserver and datacenter
Answers: 2
question
Computers and Technology, 22.06.2019 20:00
How is the number 372 written when expanded out to place values in the base 8 (octal) number system? a. 2 x 4 + 3 x 2 + 4 x 1 b. 3 x 64 + 7 x 8 + 2 x 1 c. 3 x 8 + 7 x 7 + 2 x 6 d. 3 x 100 + 7 x 10 + 2 x 1
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
question
Computers and Technology, 24.06.2019 17:00
Aman travel 200m towards east< br /> from his house then takes left< br /> to turn and moves 200 m north< br /> find the displacement & distance.< br />
Answers: 3
You know the right answer?
Def readFile(filename): dict = {} with open(filename, 'r') as infile: lines = infile. readlines() fo...
Questions
question
Mathematics, 15.09.2021 03:30
question
Biology, 15.09.2021 03:40
question
Spanish, 15.09.2021 03:40
question
World Languages, 15.09.2021 03:40