Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

frequency(d) 3 pts Given a dictionary d, where it is guaranteed that keys are strings and values are integers, return the value in d with

frequency(d) 3 pts Given a dictionary d, where it is guaranteed that keys are strings and values are integers, return the value in d with the highest occurrence. If more than one value occurs the most, return the value that appeared first in d. Tip : Create a new dictionary to keep track of value frequency You are NOT allowed to use count(), max(), min() or any other Python count libraries such as Counter and mode (No credit will be given to your code if you use them) Preconditions d: non-empty dictionary Returns: int -> value that occurs the most times in d

Preconditions

d1: dict

d2: dict

Returns: dict -> key:value pairs that appear in both d1 and d2

Examples:

>>> intersection({'a':5, 'b':7, 'd':5},{'d':5, 'a':5, 'b':9, 'c':12}) {'a': 5, 'd': 5}

>>> intersection({'a':5, 'b':7, 'd':5},{'d':8, 'a':51, 'b':9, 'c':12}) {}

>>> intersection({'a':5, 'b':7, 'd':5, 'c':'32', 't':35.6},{'d':8, 'a':1, 'b':9, 'c':'32'}) {'c': '32'}

def frequency(d): """ >>> frequency({'a':2, 'b': 2, 'c':1, 'd':1, 'e': 5, 'f': 1}) 1 >>> frequency({'a':2, 'b': 2, 'c':1, 'd':1}) 2 >>> frequency({'a':2, 'b': 2, 'c':1, 'd':1, 'h': 2, 't': 6, 'rr': 6, 'rws':6}) 2 >>> frequency({'a':2, 'b': 2, 'c':1, 'd':1, 'h': 2, 't': 6, 'rr': 6, 'rws':6, 'ret': 6, 'z': 5}) 6 """ # - YOUR CODE STARTS HERE -

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Choosing Your Topic Researching the Topic

Answered: 1 week ago

Question

The Power of Public Speaking Clarifying the

Answered: 1 week ago