Question

Using Python, Implement a function that returns an opposite of a dictionary: In order to decrypt...

  1. Using Python, Implement a function that returns an opposite of a dictionary: In order to decrypt the encrypted text, we will use the opposite of the substitution dictionary. Opposite dictionary of a dictionary is the dictionary where each value is the key and the key is the value. For instance, for the dictionary above, its opposite dictionary is

{'I': 'A', 'T': 'B', 'R': 'C', 'A': 'D', 'N': 'E', 'S': 'F', 'L': 'G', 'O': 'H', 'M': 'I', 'W': 'J', 'U': 'K', 'K': 'L', 'E': 'M', 'H': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'F': 'R', 'G': 'S', 'J': 'T', 'P': 'U', 'Q': 'V', 'V': 'W', 'X': 'X', 'Y': 'Y', 'Z': 'Z'}

Create a function named opposite(a_dict) which returns the opposite of a dictionary named a_dict

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def opposite(a_dict):
    res = dict()
    for x in a_dict.keys():
        res[a_dict[x]] = x
    a_dict = res
    return a_dict

#Testing
d = {'I': 'A', 'T': 'B', 'R': 'C', 'A': 'D', 'N': 'E', 'S': 'F', 'L': 'G', 'O': 'H', 'M': 'I', 'W': 'J', 'U': 'K', 'K': 'L', 'E': 'M', 'H': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'F': 'R', 'G': 'S', 'J': 'T', 'P': 'U', 'Q': 'V', 'V': 'W', 'X': 'X', 'Y': 'Y', 'Z': 'Z'}
print(opposite(d))

{'A': 'I', 'B': 'T', 'C': 'R', 'D': 'A', 'E': 'N', 'F': 'S', 'G': 'L', 'H': 'O', 'I': 'M', 'J': 'W', 'K': 'U', 'L': 'K', 'M': 'E', 'N': 'H', 'O': 'B', 'P': 'C', 'Q': 'D', 'R': 'F', 'S': 'G', 'T': 'J', 'U': 'P', 'V': 'Q', 'W': 'V', 'X': 'X', 'Y': 'Y', 'Z': 'Z'}
Add a comment
Know the answer?
Add Answer to:
Using Python, Implement a function that returns an opposite of a dictionary: In order to decrypt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a Python Program Write a program that encrypts letters based on the following key....

    This is a Python Program Write a program that encrypts letters based on the following key. Original letter to encrypted letter A M B L C K D J E I F H G G H F I E J D K C L B M A N Z O Y P X Q W R V S U T T U S V R W Q X P Y O Z N Write the output to a file

  • why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',...

    why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A'}, {'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, }; for(int...

  • 12.22 Chapter 4: Encrypt Characters Simple Caesar Cipher challenge. You'll need to correct code to print...

    12.22 Chapter 4: Encrypt Characters Simple Caesar Cipher challenge. You'll need to correct code to print ciphertext character correctly. With offset of 3 the output should be ORIGINAL CHARACTERS A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ENCRYPTED CHARACTERS D E F G H I J K L M N O P Q R S T U V W X Y Z...

  • Please explain the python code below L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42,...

    Please explain the python code below L1 = [2, 15, 'Carol', 7.4, 0, -10, -6, 42, 27, -1, 2.0, 'hello', [2, 4], 23] print("L1 =",L1) odds =[] evens=[] list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',',','.'] no=0 for i in L1: i=str(i) for j in list: if i.find(j)>=0: no=1 if no==1: None else: i=int(i) if i%2==0: evens.append(i) else: odds.append(i) no=0      ...

  • Write a python program that writes to an output file "decoder.txt" a table of letters as...

    Write a python program that writes to an output file "decoder.txt" a table of letters as follows: ___1_2_3_4_5 1: A B C D E 2: F G H I K 3: L M N O P 4: Q R S T U 5: V W X Y Z Note that the letter J has been removed. Use string.ascii_uppercase to start

  • I NEED A MATHEMATICAL ALGORITHM FOR A CEASER CHYPER I CREATED. PLEASE HELP ME...THANK YOU! THE...

    I NEED A MATHEMATICAL ALGORITHM FOR A CEASER CHYPER I CREATED. PLEASE HELP ME...THANK YOU! THE SINGLE-DIGIT KEY IS 14 THE PHRASE IS "GOOD MORNING PROFESSOR" THE CYPHER IS UCCR ACFBWBU DFCTSGGCF I DON'T KNOW HOW TO CREATE THE ALGORITHM AND IT CANNOT BE COMPUTER GENERATED. a. Develop a Caesar cipher-type encryption algorithm with a little more complexity in it. For example, the algorithm could alternatively shift the cleartext letters positive and negative by the amount of the key value....

  • def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or...

    def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...

  • Java... Write a program that has 4 separate threads. The threads will have the following arrays:...

    Java... Write a program that has 4 separate threads. The threads will have the following arrays: Thread1: A E I M Q U Y Thread2: B F J N R V Z Thread3: C G K O S W ThreadD: D H L P T X Your goal is to synchronize the threads in such a way that they print out all the letters of the alphabet in order.

  • Spell it out! Use the following Java concepts to compile the program below:   String myName =...

    Spell it out! Use the following Java concepts to compile the program below:   String myName = "Chuck";     int length = myName.length();     char firstChar = myName.charAt(0);     char secondChar = myName.charAt(1);     if (myName.equals("Tom")) {       System.out.println ("Sorry, Tom!");   } Write a program that uses a METHOD to translate these individual characters:   input output input output input output input output input output a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t...

  • *Python Draw a bargraph of English letter frequency Also save the bargraph in a file #...

    *Python Draw a bargraph of English letter frequency Also save the bargraph in a file # (1) import necessary modules/packages/libaries # A dictionary containing the information of English letter frequency freq = {'a':8.17, 'b':1.49, 'c':2.2, 'd':4.25, 'e':12.7, 'f':2.23, 'g':2.02, 'h':6.09, 'i':7.0, 'j':0.15, 'k':1.29, 'l':4.02, 'm':2.41, 'n':6.74, 'o':7.5, 'p':1.92, 'q':0.09, 'r':5.99, 's':6.33, 't':9.36, 'u':2.75, 'v':0.98, 'w':2.56, 'x':0.15, 'y':1.99, 'z':0.08} labels = [] data = [] # (2) extract data from dictionary freq to make two lists: # labels contains all keys...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT