Question

In: Computer Science

I have this mystery code. I dont know what the code does. Can somone please explain...

I have this mystery code. I dont know what the code does. Can somone please explain with examples. (python 3.xx)

from typing import Dict, TextIO, Tuple, List
def exam(d1: Dict[str, List[int]], d2: Dict[int, int]) -> None:
""" *Mystery code*

"""
for key in d1:
value = d1[key]
for i in range(len(value)):
value[i] = d2[value[i]]
  

Solutions

Expert Solution

Explanation:

The exam method takes input as two dictionaries d1 and d2.

The dictionary d1 has a string value as key and list of integers as value.

The dictionary d2 has interger value as key and integer value as value

This code can be understood using a example.

Consider the exam function has two dictionaries d1 and d2 such that d1 has exam_name as key and list of integers as value.

These list of integers represent studentid's which are integers.

The dictionary d2 has student id as key and marks as value.

See that for every value from the list of integers in d1,there must be an entry in d2.

This represent the marks of that student.

The outer loop iterates based on number of exams.
The inner loop iterates based on number of students in each exam.

For each exam,the student ids are considered.
For each student id,the marks are found using d2 and stored in value list.

See that the value list is printed and it has the marks of students for those respective exams.


Related Solutions

Can you add more comments explaining what this code does? i commented what I know so...
Can you add more comments explaining what this code does? i commented what I know so far #include<stdio.h> #include<pthread.h> #include<semaphore.h> #include<unistd.h> sem_t mutex,writeblock; int data = 0,rcount = 0; int sleepLength = 2; // used to represent work void *reader(void *arg) { int f; f = ((int)arg); sem_wait(&mutex); // decrement by 1 if rcount = rcount + 1; if(rcount==1) sem_wait(&writeblock); sem_post(&mutex); printf("Data read by the reader%d is %d\n",f,data); //shows current reader and data sleep(sleepLength); // 1 second of "work" is...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
I have this exercise and i dont know how to do it DDB Corporation was formed...
I have this exercise and i dont know how to do it DDB Corporation was formed by twenty-four shareholders on January 1, 2017. The shareholders will be having their semi-annual meeting on September 28, 2018 to review the financial results for January 1 – June 30, 2018. As of January 1, 2018, the company has a retained deficit (this means the company incurred a net loss in 2017). The following are the unadjusted balances of DDB Corporation as of June...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also please type it out so theres no confusion thank you -- Code your design here library IEEE; use IEEE.std_logic_1164.all; -- entity declaration for testbench entity test mux2 is end test; --architecture Body declaration for 2to1 mux -- component declaration of source entity 2to1 mux component test mux2 is port ( sel : in std_logic ; --select input, A : in std_logic ; --data input...
I know the code isn't here nut please answer as much as you can thanks! it...
I know the code isn't here nut please answer as much as you can thanks! it is qt creator c++ Question 1 Which of the following is a correct description of ItemList ? It is a QMap and thus an ItemList object is a QMap itself It has a QMap, which cannot be accessed outside this class ItemList uses a heap QMap object QMap used by ItemList uses Item pointers as keys Question 2 Which of the following is true...
i dont know what is the Plant Clearing Offset By Biobanking Agreement, i need the answer...
i dont know what is the Plant Clearing Offset By Biobanking Agreement, i need the answer in detail
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
I dont know what to do: Is there a significant difference between drug type and mean...
I dont know what to do: Is there a significant difference between drug type and mean relative-change* of Cholesterol from screening to follow up? * Relative Change = (Follow up - Initial) / Initial Patient ID Drug Stomach Pain Sex Age Height Systolic BP Diastolic BP Exercise Coffee Consumption Alcohol Consumption Weight Weight3 Cholesterol Cholesterol3 Triglycerides Triglycerides3 HDL HDL3 LDL LDL3 1 B Yes F 22 67.13 124 78 180 1 > 2 138 145 197 182 152 135 43...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
Please, explain to me how can I know when I need to use z- table and...
Please, explain to me how can I know when I need to use z- table and when to use t-table distribution. Please, be as detailed as you can. I want to look a problems and know which one I need.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT