Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python Suppose that you are given a dictionary. It's easy to search through the keys - that's what dictionaries are best at. But how

in python

image text in transcribed

Suppose that you are given a dictionary. It's easy to search through the keys - that's what dictionaries are best at. But how do you search based on values??? Write a function that takes a dictionary as its only parameter. Build a loop that iterates through the keys. Look at the value for each one. Keep track of the key which has the maximum value. Return that key from the function. The second part of this ICA was disabled, because it was too chal- lenging for an in-class activity. As a second step, take your code, and add a little bit to it, so that it can also find the key associated with the second largest value. Return both keys, like this: return first, second You can call a function like this, which returns two values, and save the results like this: a, b = function_that_returns_two_things (some_param) EXAMPLE: Key Value foo bar baz fred 1234 888888 -1 256 The key associated with the maximum value, from the example above, would be "bar", because it's associated with the value 888888. The key associated with the second would be "foo", which is associated with 1234

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions