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
Matching parentheses. An math expression may have a number of parentheses like (, ), [, ], { and }. Each openning parenthesis (,
Solnce55 [7]
C++ Code

#include
using namespace std;

bool match(const char exp[],const int s)
{
// declare a character array to perform stack operations
char stack[s];

// declare top and initialize to -1 and flag to 0
int top=-1,i,flag=0;

// visit all characters in the expression string
for(i=0;i {
// if the character is [ or ( or { then push it into stack
if(exp[i]=='[' || exp[i]=='(' || exp[i]=='{')
{
top++;
stack[top]=exp[i];
}
// if the character is ] or ) or } then check conditions
else if(exp[i]==']' || exp[i]==')' || exp[i]=='}')
{
// check stack is empty or not
if(top!=-1)
{
// check all possible failure conditions
if(exp[i]==')' && (stack[top] == '{' || stack[top]=='['))
{
flag = 1;
break;
}
else if(exp[i]==']' && (stack[top] == '{' || stack[top]=='('))
{
flag = 1;
break;
}
else if(exp[i]=='}' && (stack[top] == '(' || stack[top]=='['))
{
flag = 1;
break;
}
top--;
}
else
{
flag=1;
break;
}
}
}
// after visiting all characters of expression string check if stack is not empty and flag is 1. if any one of the condition is true return false. otherwise return true

if(top>=0 || flag==1)
return false;
else
return true;
}

int main()
{

// declare character array to store expression
char exp[10000];
cout<<"Enter an Expression"<
// read expression from user
cin.getline(exp, 10000);
int s=0;

// find the length of the expression string
for(int i=0;exp[i]!='\0';i++)
{
s++;
}

// call the match function
bool status = match(exp,s);

// print the result based on value returned by match() function
if(status == 1)
cout<<"true"< else
cout<<"false"<
}


Sample Input/Output is attached

3 0
2 years ago
They always water the garden in the morning. (Underline the verb in the sentence)​
valina [46]

Answer:

Water

Explanation:

A verb describes an action, an occurrence, or a state of being. Watering is an action.

8 0
3 years ago
Read 2 more answers
Alguien porfavor me dice como cambiar de idioma en brainly
Marat540 [252]

Answer:

no lo siento

Explanation:

4 0
2 years ago
Read 2 more answers
If you save a Word file as a Web page, what type of file will it be?
Mnenie [13.5K]

Answer:

When you save a Microsoft Word document as a Web page (on the File menu, click Save as Web Page), Word automatically converts the page to HTML (Hypertext Markup Language), the language used by Web browsers to read Web pages.

Explanation:

7 0
3 years ago
Explaing why the findings are different between a general purpose search engine ( google) and a meta search engine ( ask jeeves)
Softa [21]
A lot of people use google and on all search engines the sites are ordered in what people click on the most. Popularest website that fits in with the key words and different people used different websites and different search engines
6 0
3 years ago
Other questions:
  • What is the name of a computer or application program that intercepts user requests from the internal secure network and then pr
    11·1 answer
  • My computer have black spots and line
    7·2 answers
  • What is the difference between Google and a subject directory like Yahoo Directory or Infomine?
    14·2 answers
  • The reliance on _____ as the design methodology for relational databases is seen as a stumbling block to its use in OLAP systems
    5·1 answer
  • A two-dimensional array of characters can contain Group of answer choices
    11·1 answer
  • Which of the following is NOT a fall prevention system?
    12·2 answers
  • SOMEONE HELP PLEASE ​
    5·1 answer
  • 1. It is acceptable to use a jack that has been
    13·1 answer
  • A new president has been elected. She promises to lower taxes drastically. What is most LIKELY to happen as a result of this dec
    8·1 answer
  • 45 points!
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!