Question

In python def reverse_lookup(input_dict, test_value): # Complete this function to find all the keys in a...

In python

def reverse_lookup(input_dict, test_value):
# Complete this function to find all the keys in a dictionary that map to the input value.
# input1: input_dict (dict)
# input2: test_value
# output: list of keys

# YOUR CODE HERE

It has to pass these tests

input_dict = {
'January': 31,
'February': 28,
'March': 31,
'April': 30,
'May': 31,
'June': 30,
'July': 31,
'August': 31,
'September': 30,
'October': 31,
'November': 30,
'December': 31,
}

assert reverse_lookup(input_dict, 31) == ['January', 'March', 'May', 'July', 'August', 'October', 'December']

Homework Answers

Answer #1
def reverse_lookup(input_dict, test_value):
    # Complete this function to find all the keys in a dictionary that map to the input value.
    # input1: input_dict (dict)
    # input2: test_value
    # output: list of keys

    # YOUR CODE HERE
    result = []
    for x in input_dict:
        if input_dict[x]==test_value:
            result.append(x)
    return result


input_dict = {
'January': 31,
'February': 28,
'March': 31,
'April': 30,
'May': 31,
'June': 30,
'July': 31,
'August': 31,
'September': 30,
'October': 31,
'November': 30,
'December': 31,
}

assert reverse_lookup(input_dict, 31) == ['January', 'March', 'May', 'July', 'August', 'October', 'December']

Know the answer?
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
Similar Questions
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple three-month moving average for each month for both companies. (Input all amounts as positive values. Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 175.04 $ 613.41 February 176.89 623.12 March 191.47 574.07 April 207.78 547.70 May 192.37 510.30 June 208.63 495.58 July 234.49 606.39 August 204.16 536.91 September 220.55 512.70 October 214.59 601.73 November 196.34 591.56...
Problem 8-3 Simple Moving Averages (LO4, CFA1) The table below shows the closing monthly stock prices...
Problem 8-3 Simple Moving Averages (LO4, CFA1) The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple three-month moving average for each month for both companies. (Input all amounts as positive values. Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 174.44 $ 611.96 February 176.49 622.04 March 190.21 575.48 April 206.45 547.30 May 192.85 512.38 June 208.17 496.78 July 233.16 606.09 August 205.39 537.36 September 220.07...
Incidents By Month For 2018 January 5,400 MEAN MEDIAN MODE February 4,930 5,181 5,216 5260 March...
Incidents By Month For 2018 January 5,400 MEAN MEDIAN MODE February 4,930 5,181 5,216 5260 March 5,330 April 5,042 May 5,143 June 5,172 July 5,260 August 5,260 September 5,339 October 5,283 November 4,909 December 5,109 Is it a standard distribution, why or why not?
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential three-month moving average for both stocks where two-thirds of the average weight is placed on the most recent price. (Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 181.04 $ 627.91 February 180.89 633.92 March 204.07 559.97 April 221.08 551.70 May 187.57 489.50 June 213.23 483.58 July 247.79 609.39 August 191.86 532.41 September 225.35 510.10 October 215.79...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential three-month moving average for both stocks where two-thirds of the average weight is placed on the most recent price. (Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 177.44 $ 619.21 February 178.49 627.44 March 196.51 568.43 April 213.10 549.30 May 190.45 501.98 June 210.47 490.78 July 239.81 607.59 August 199.24 535.11 September 222.47 511.66 October 215.07...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the exponential three-month moving average for both stocks where two-thirds of the average weight is placed on the most recent price. (Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 170.84 $ 603.26 February 174.09 615.56 March 182.65 583.94 April 198.47 544.90 May 195.73 524.86 June 205.41 503.98 July 225.18 604.29 August 212.77 540.06 September 217.19 514.52 October 213.75...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple three-month moving average for each month for both companies. (Input all amounts as positive values. Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 173.84 $ 610.51 February 176.09 620.96 March 188.95 576.89 April 205.12 546.90 May 193.33 514.46 June 207.71 497.98 July 231.83 605.79 August 206.62 537.81 September 219.59 513.22 October 214.35 599.71 November 195.44 593.30...
Demand for stereo headphones and MP3 players for joggers has caused Nina Industries to grow almost...
Demand for stereo headphones and MP3 players for joggers has caused Nina Industries to grow almost 50 percent over the past year. The number of joggers continues to expand, so Nina expects demand for headsets to also expand, because, as yet, no safety laws have been passed to prevent joggers from wearing them. Demand for the players for last year was as follows: MONTH DEMAND (UNITS) January 4,210 February 4,310 March 4,010 April 4,410 May 5,010 June 4,710 July 5,310...
In Matlab: A list of average monthly high temperatures for the city of Monroe Louisiana is...
In Matlab: A list of average monthly high temperatures for the city of Monroe Louisiana is given below: Month Temperature (in◦F) January 56 February 60 March 69 April 77 May 84 June 90 July 94 August 94 September 88 October 79 November 68 December 58 For convenience, label January as 1, February as 2, and so forth. Then fit a quadratic and fourth-degree polynomials through these data on the same figure window. Include the label and a legend. Based on...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple...
The table below shows the closing monthly stock prices for IBM and Amazon. Calculate the simple three-month moving average for each month for both companies. (Input all amounts as positive values. Do not round intermediate calculations. Round your answers to 2 decimal places.) IBM AMZN January $ 169.64 $ 600.36 February 173.29 613.40 March 180.13 586.76 April 195.81 544.10 May 196.69 529.02 June 204.49 506.38 July 222.52 603.69 August 215.23 540.96 September 216.23 515.04 October 213.51 592.64 November 192.29 599.39...