1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lynna [10]
3 years ago
15

Make a Backwards Phonebook from a Regular Phonebook

Computers and Technology
1 answer:
Dima020 [189]3 years ago
7 0

Answer:

Code in Python is given. Take note of the instruction in bold font

Explanation:

You will need to update the below two lines in your system based on the file path -

backward_phone_number('F:\\phone_number_input.txt','F:\\phone_number_output.txt')

def backward_phone_number(input_file,output_file):

   ph_num_dictionary={}

   entries=[]

   #########################################################

   with open(input_file,'r') as read_file:

       entries=read_file.readlines()[1:]

   for entry in entries:

       ph_num_name=entry.split()

       ph_number=ph_num_name[1].strip()

       name=ph_num_name[0].strip()

       if ph_num_dictionary.get(ph_number)==None:

           name_list=[name]

           ph_num_dictionary[ph_number]=name_list

       else:

           ph_num_dictionary.get(ph_number).append(name)

   #########################################################

   ph_num_dictionary = dict(sorted(ph_num_dictionary.items(),key=lambda pair:pair[0]))

   with open(output_file,'w+') as write_file:

       write_file.write('Telephone Number\tName\r\n')

       for num,name in ph_num_dictionary.items():

           if len(name)==1:

               write_file.write(num+'\t'+name[0]+'\r\n')

           else:

               name.sort()

               for person in name:

                   write_file.write(num + '\t' + person + '\r\n')

backward_phone_number('F:\\phone_number_input.txt','F:\\phone_number_output.txt')

You might be interested in
Help me please, I'm attempting a test<br>​
dusya [7]
It’s A it’s a keyboard
8 0
2 years ago
Read 2 more answers
Explain program and programming with two examples of each<br>Help​
evablogger [386]

Answer:

program (noun) is executable software that runs on a computer. ... Examples of programs include Web browsers, word processors, e-mail clients, video games, and system utilities. These programs are often called applications, which can be used synonymously with "software programs." On Windows, programs typically have an .

7 0
3 years ago
The Counter Pattern
kumpel [21]
You'll probably see numbers counting up, like 1 2 3 4 ...
6 0
3 years ago
True / Fasle
Liono4ka [1.6K]

Answer:

False

Explanation:

3 0
3 years ago
PLEASE HELP ASAP 100 POINTS AND BRAINLIEST
Sergio [31]

Answer:

what is the question

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • What term is used to describe a chipset developed and promoted by the U.S. government from 1993 to 1996 as an encryption device
    9·1 answer
  • Here is a Test Code segment:
    13·1 answer
  • With a patent on drug Z27, why would Able Drug Company charge customers $7 per 100 units even though its cost of producing 100 u
    5·2 answers
  • In a ___ traversal of a binary tree, you begin at the root and visit nodes one level at a time
    10·1 answer
  • Drag each storage device to its category.
    7·1 answer
  • Technician A says that PTC heaters can be built into a conventional heater core assembly. Technician B says that a PTC heater's
    11·1 answer
  • Many of the first photographers were actullay scientists and inventors
    11·1 answer
  • ___________ is related to mass, but also includes the gravitational pull of the Earth.
    14·1 answer
  • A user input is when the user interacts with the program by typing.<br> True<br> False
    11·2 answers
  • Which directory stores the cron configuration file?.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!