Suppose you are given a list of contacts as input. Your task is to create a “Phonebook” out of those contacts based on their telecom operator. The phonebook is nothing but a nested dictionary which is made of 1 rule: 1.You have to save each contact based on their telecom operator. If there is no contact of a specific telecom operator, that operator should not be shown in the phone book. If a contact number, Starts with ‘017’ or ‘013’ then the telecom operator is Grameenphone Starts with ‘018’ then the telecom operator is Robi Starts with ‘016’ then the telecom operator is Airtel Starts with anything else then the telecom operator is Others While printing the phonebook as output the contacts under each telecom operator should be shown in alphabetically sorted order based on the contact names. See the sample output for clarification. [N.B: The telecom operator names can appear in any order but the contacts under each telecom operator should appear in alphabetical order.] Sample Input: Bob 01632342392 Alice 01346734123 Britney 01803544535 Aeron 01723454642 Smith 01923457890 Tarek 01866392233 Sample Output:(No need to follow this output format. Just print the resultant sorted dictionary. ) { Airtel: { Bob:01632342392 } Grameenphone: { Aeron:01723454642 Alice:01346734123 } Robi: { Britney:01803544535 Tarek:01866392233 } Others: { Smith:01923457890 } }
Suppose you are given a list of contacts as input. Your task is to create a “Phonebook” out of those contacts based on their telecom operator. The phonebook is nothing but a nested dictionary which is made of 1 rule:
1.You have to save each contact based on their telecom operator. If there is no contact of a specific telecom operator, that operator should not be shown in the phone book. If a contact number,
Starts with ‘017’ or ‘013’ then the telecom operator is Grameenphone
Starts with ‘018’ then the telecom operator is Robi
Starts with ‘016’ then the telecom operator is Airtel
Starts with anything else then the telecom operator is Others
While printing the phonebook as output the contacts under each telecom operator should be shown in alphabetically sorted order based on the contact names. See the sample output for clarification.
[N.B: The telecom operator names can appear in any order but the contacts under each telecom operator should appear in alphabetical order.]
Sample Input:
Bob 01632342392 Alice 01346734123 Britney 01803544535 Aeron 01723454642 Smith 01923457890 Tarek 01866392233
Sample Output:(No need to follow this output format. Just print the resultant sorted dictionary. )
{
Airtel:
{
Bob:01632342392
}
Grameenphone:
{
Aeron:01723454642
Alice:01346734123
}
Robi:
{
Britney:01803544535
Tarek:01866392233
}
Others:
{
Smith:01923457890
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images