Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Python code
Python
Write a function named `freq(l)` that takes a list `l` of numbers
and returns a tuple of the most frequent number and its frequency.
For example, `freq([1,2,3,4,5,2,3,4,5,3,4,5,4,5,4]) returns (4,5)
because number 4 appears 5 times in this list. If multiple numbers
appear as most frequent, then the first element of the returned
tuple is a list of all those numbers. For example,
freq([1,2,3,1,2,1,2,3,1,2]) will return ([1,2], 4) because both
1 and 2 appear 4 times in the list.
"""
def freq(l):
# remove the following line to solve this question
return
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function called remove_odd that takes a list of numbers that have both even and odd numbers mixed.# Function should remove all the odd numbers and return a compact list which only contains the even numbers. Example1: Function Call:remove_odd ([21, 33, 44, 66, 11, 1, 88, 45, 10, 9])Output:[44, 66, 88, 10]arrow_forwardPlease I need it quickly !!! In python We have a list (named data) of numbers sorted in ascending order, for example: data = [2, 4, 5, 9, 10, 12, 13, 17, 18, 20] Write a function (named DataVar(data)), which take a list (data) as input parameter and performs the following steps on the list: 1) it finds the mean m of the data (for the given example, it is m = (2 + 4 + 5 + 9 + 10 + 12 + 13 + 17 + 18 + 20)/10 =110/10 = 11). 2) then, it finds the difference of data and m. Essentially, it finds for all data: Diff = data-m For the given example, Diff = [-9, -7, -6, -2, -1, 1, 2, 6, 7, 9]. 3) then, it finds the sum of Diff and 7. Essentially, it finds for all data: Sums = Diff+7 For the given example, Sums = [-2, 0, 1, 5, 6, 8, 9, 13, 14, 16]. 4) then, it finds the square of all the elements of Sums, such that Squares = square of the elements of Sums. For the given example, Squares = [4, 0, 1, 25, 36, 64, 81, 169, 196, 256]. 5) it finds the average of Squares and stores it in result, and…arrow_forwardWrite a function little_sum (number_list, limit) that returns the sum of only the numbers in number_list that are less than or equal to the given limit. In this question you must use a for loop and you are not allowed to use the sum function. For example: Test Result numbers = [1, 2, 3, 4, 5, 6] total = little_sum(numbers, 3) print(total) values = [6, 3, 4, 1, 5, 2] 10 total = little_sum(values, 4) print(total)arrow_forward
- This is for Python version 3.8.5 and please include pseudocode. nums = [8, 15, 6, 17, 33, 20, 14, 9, 12]Write Python code that: uses a function to print the size of the list named nums uses a function to print the largest number in nums prints the element 14 by using its index makes a slice named subnums containing only 33, 20, and 14arrow_forwardUse Python when answering the question: Write a function primeFac that computes the prime factorization of anumber: it accepts a single argument, an integer greater than 1 it returns a list containing the prime factorization each number in the list is a prime number greater than 1 the product of the numbers in the list is the original number the factors are listed in non-decreasing order Output is in the attached picture:arrow_forwardWrite a function called find_duplicates which accepts one list as a parameter. This function needs to sort through the list passed to it and find values that are duplicated in the list. The duplicated values should be compiled into another list which the function will return. No matter how many times a word is duplicated, it should only be added once to the duplicates list. NB: Only write the function. Do not call it. For example: Test Result random_words = ("remember","snakes","nappy","rough","dusty","judicious","brainy","shop","light","straw","quickest", "adventurous","yielding","grandiose","replace","fat","wipe","happy","brainy","shop","light","straw", "quickest","adventurous","yielding","grandiose","motion","gaudy","precede","medical","park","flowers", "noiseless","blade","hanging","whistle","event","slip") print(find_duplicates(sorted(random_words))) ['adventurous', 'brainy', 'grandiose', 'light', 'quickest', 'shop', 'straw', 'yielding']…arrow_forward
- -python- Write a function called get_words that takes a list of words and a letter,and returns a new list, which only contains the words that don't have the given letter in them. For example, get_words(["cat", "dog"], 'o') should return ["cat"] and get_words(["cat", "bat"], 'a') should return an empty list.arrow_forwardIn python We have a list (named data) of numbers sorted in ascending order, for example: data = [2, 4, 5, 9, 10, 12, 13, 17, 18, 20] Write a function (named DataVar(data)), which take a list (data) as input parameter and performs the following steps on the list: 1) it finds the mean m of the data (for the given example, it is m = (2 + 4 + 5 + 9 + 10 + 12 + 13 + 17 + 18 + 20)/10 =110/10 = 11). 2) then, it finds the difference of data and m. Essentially, it finds for all data: Diff = data-m For the given example, Diff = [-9, -7, -6, -2, -1, 1, 2, 6, 7, 9]. 3) then, it finds the sum of Diff and 7. Essentially, it finds for all data: Sums = Diff+7 For the given example, Sums = [-2, 0, 1, 5, 6, 8, 9, 13, 14, 16]. 4) then, it finds the square of all the elements of Sums, such that Squares = square of the elements of Sums. For the given example, Squares = [4, 0, 1, 25, 36, 64, 81, 169, 196, 256]. 5) it finds the average of Squares and stores it in result, and returns it. For the given…arrow_forwardProgramming language is latest version of pythonarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education