Question

Must be written in python 3:

☆ Dictionary Ordered Array Given two arrays of numbers, we can use dictionary ordering to identify which array is smaller

#
# Complete the 'SmallestDictionaryOrderedArray' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER_ARRAY a
# 2. INTEGER_ARRAY b
#

def SmallestDictionaryOrderedArray(a, b):
# Write your code here

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

[-3, 9, 4, -19, 7] £ GG GGgg main.py saved def SmallestDictionaryOrderedArray(a, b): #if any of the array has elements it is

code:

def SmallestDictionaryOrderedArray(a, b):

#if any of the array has 0 elements it is the smaller

if len(a) == 0:

return a

if len(b) == 0:

return b

for i in range(len(a)):

#if array a has more elements than array b

if i>=len(b):

return b

#check if element in a is greater than b

if a[i] > b[i]:

return b

elif b[i] > a[i]:

return a

#if no results found then array b has more elements than array a

#array a is Smaller

return a

print(SmallestDictionaryOrderedArray([-3,9,4,8,15],[-3,9,4,-19,7]))

print(SmallestDictionaryOrderedArray([4,0,-5],[5]))

print(SmallestDictionaryOrderedArray([4,0,-5],[9,8]))

print(SmallestDictionaryOrderedArray([4,1],[4,0,-5]))

print(SmallestDictionaryOrderedArray([4,0,-5],[4,0,4]))

print(SmallestDictionaryOrderedArray([4,0,-5],[4,0,-5,0]))

print(SmallestDictionaryOrderedArray([4,0,-5,0],[4,0,-5]))

Add a comment
Know the answer?
Add Answer to:
Must be written in python 3: # # Complete the 'SmallestDictionaryOrderedArray' function below. # # The...
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
  • Question 2 In this question, you will read two data files that include integers into two...

    Question 2 In this question, you will read two data files that include integers into two different arrays – the same way we did in class (but we are doing to arrays here). Duplicates are ok. 1- After you read the data into the array (use one function that takes an int array and a dsize by reference just like we did in class, and call that from main to fill both arrays). 2- Include a printArray function so that...

  • In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as...

    In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line: At first, I have an empty dictionary then to that I...

  • In Python 3 5) Make a dictionary of all the words from the below paragraph, which...

    In Python 3 5) Make a dictionary of all the words from the below paragraph, which are having 4 or more letters in it. • Key of the dictionary should be word and value should be the number of times that word has appeared in the paragraph, sort the dictionary in descending order. eg. {'girls': 2, 'part': 2, 'equal': 2, "it's": 1} • Write a brief explanation walking through your code's logic in markdown. paragraph = "" "It's the Spice...

  • This is a python task. 2.3 Count Rated Ballots (5 points Complete and test the function...

    This is a python task. 2.3 Count Rated Ballots (5 points Complete and test the function count_rated: • Input: a list of rated ballots • Here, on cach ballot, the voter gave cach candidate a score out of 5. Sum up the scores for cach candidate. • Return: a dictionary of how many points cach candidate got Example: >>> count_rated('LIBERAL': 5, 'NDP':2}, {'NDP':4, GREEN':5}]) {'LIBERAL': 5, 'NDP': 6, 'GREEN': 5} Electing a winner this way is called Score voting or...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords,...

    please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords, Y_coords) below, which should take two arrays of equal length containing the x-andy- coordinates for some number of particles. We'll use a very simple random walk algorithm • For each particle, choose a random angle between 0 and 2 • The particle moves by 1 unit of distance in the direction given by d.o. It is displaced by (Ax, Ay) (cos, sino). We'll do...

  • Must be written in C 89 Mode Array Insertion Your task is to complete the implementation...

    Must be written in C 89 Mode Array Insertion Your task is to complete the implementation of the insertion function, insert_into_array: int* insert_into_array(int arr[], size_t arr_len, int value, size_t pos); The insertion function inserts a value into an array at a specified position. All elements to the right of the inserted element are shifted over a position (upon inserting, all elements at the insertion position are shifted up an index, and the last element in the array is overwritten by...

  • The following are short Python calculations. Give the answer and the Python code for each. 1....

    The following are short Python calculations. Give the answer and the Python code for each. 1. What is the sum of the numbers from 22:100 incrementing by 2? Do this in two ways: Use a while statement and a for loop to do the calculation. (Hint: make sure the numbers include 100) 2. What is the mean, standard deviation of the square root of the numbers from 3 to 5 incrementing by 0.1? Use the linspace function from the numpy...

  • (9) Complete the below Java method recursively, which takes in a String and returns if it's...

    (9) Complete the below Java method recursively, which takes in a String and returns if it's a palindrome. Remember a palindrome means a string that is the same reversed, like "deed", "racecar" or "tacocat". The empty string "" is also a palindrome. public boolean isPalindrome (String word) { (8) (a) (8 points) Implement merging two sorted arrays into one sorted ar- ray. These arrays are sorted in descending order. For example, (5, 4, 2). Return an array with all the...

  • Write the function in python and show the code 2. Write a function jscore (s1, s2)...

    Write the function in python and show the code 2. Write a function jscore (s1, s2) that takes two strings s1 and s2 as inputs and returns the Jotto score of s1 compared with s2 -.e., the number of characters in s1 that are shared by s2. The positions and the order of the shared characters within each string do not matter. Repeated letters are counted multiple times, as long as they appear multiple times in both strings. For example...

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