Question

Use the FDR to design and write a function, maxValTimes, that takes a list of integers...

Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.  

For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times).

For full marks, please note the following:

Proper indentation and syntax are required.

You may use Python's built in list functions len and count, and set function add.  You may not use any other Python functions.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

def maxValTimes(l):
size=len(l)
max=l[0]
for i in l:
if i>max:
max=i
fmax=l.count(max)
s=set(l)
r=set()
for x in s:
if l.count(x) == fmax:
r.add(x)
return r
  
l=[2,1,1,2,3,3,1]
print(maxValTimes(l))
  

Screenshot:

1, def maxValTimes (1): 2 size-len(1) 3 max=1[@] 4, for i in 1: 5. if i>max: 6 max-i 7 fmax=1.count(max) 8 s=set(1) 9 r=set()

Add a comment
Know the answer?
Add Answer to:
Use the FDR to design and write a function, maxValTimes, that takes a list of integers...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Write a function maxList that takes in a list of integers as argument and returns their...

    Write a function maxList that takes in a list of integers as argument and returns their highest. You may not use the max() or the sorted() Python built-in functions.

  • Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e....

    Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return: 1. List (of tuples) containing all pairs of numbers in L that are coprime. 2. Empty list, If no pair of numbers in L is coprime. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is...

  • Python: Create a function count_target_in_list that takes a list of integers and the target value then...

    Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • Write a function that takes, as an argument, a list of positive integers and a target...

    Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.

  • The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of...

    The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of integer containing the coordinates of the consecutive vertices of a polygon. The function largest_edge_group returns the size of the largest group of same length edges. Your function must run in O(n), where n is the length of vertices. Example largest_edge_group([[0,0],[1,1],[0,2],[-2,3],[-1,2]]) => 3 Hint Remember, it is not possible to compare Floats for strict equality, but since the coordinates are integers, the squared distance is...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • PYHTON Write a function which takes a single parameter. The parameter is a list of integers....

    PYHTON Write a function which takes a single parameter. The parameter is a list of integers. Your function should return a count of the number of integers in the list which are odd

  • Write a Python function powerSet() that takes in a finite list object AA and returns P(A)P(A),...

    Write a Python function powerSet() that takes in a finite list object AA and returns P(A)P(A), the power set of A. The output should be only in the form of list objects. Note: Make sure you are familiar with some of Python's basic built-in list functions and operators, as they will make completing this problem far easier. For example: Test Result A = [0, 1, 2] output = set([frozenset(a) for a in powerSet(A)]) expected = [[], [0], [0, 1], [2],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT