Write a function called count_items() that takes a list and returns a dictionary that contains the number of times list items occurred. Write Python statements that test your function. Part-2: Sample list= ['Mercedes', 'Bentley', 'Audi', 'Bentley', 'Tesla', 'Mercedes'] Result= {'Mercedes': 2, 'Bentley': 2, 'Audi': 1, 'Tesla': 1}
Q: Write a function high_low_dict(numbers, sep) that takes a list of numbers and an int sep that will…
A: Note: The problem solved in JAVA. ALGORITHM: -> take a ArrayList to add elements and an int type…
Q: Write a function remove_smallest() that gets a dictionary as a parameter and remove the item which…
A: def remove_smallest(data): #find min value in dict value=min(data.values()) #create new…
Q: Write a function removeRange() that takes a list of integer numbers and two integer numbers as…
A: RemoveRange() :- The removeRange() method of Vector in Java is used to remove all elements within…
Q: Write a function that takes two arguments: stock and ingr (short for ingredients) and returns the…
A: stock = {"salt":100,"sugar":100,"flour": 50,"apple":3,"cream":10}ingr =…
Q: Write a function that takes two arguments: stock and ingr (short for ingredients) and returns the…
A: Given: To write a python program to check the availability of ingredients in the stock.
Q: Write a function create_list_MtoN that will create and return a list of integers from m to n (where…
A: def create_list_Mton(m,n): lis=[] if(m>n): # for m is greater than n for…
Q: You have been asked to write a function that supplies the "reverse lookup" name for the person…
A: 1) Below is the updated program to return name for the person associated with phone_num It defines…
Q: Write a function randomList() that gets three integers as parameters, start, bound and k. This…
A: In Python, to generate a list of random numbers with specified ranges and sizes, random.sample()…
Q: Define a function called create_numbers_dictionary (numbers) which takes a list of integers as a…
A: The program is written in Python. Check the program screenshot for the correct indentation. Please…
Q: python code Write a Python function listDictPrime() that gets as parameter a list of integers,…
A: Given Solution Contains: listDictPrime() function. Screenshot of code of listDictPrime() function.…
Q: Write a function lastDigits() that takes a list of numbers as parameter, returns a string made of…
A: Required: Write a function lastDigits() that takes a list of numbers as parameter, returns a string…
Q: Write the python function named keep_even_values. This function will have 1 parameter that will be a…
A: iterate from i=0 to len(lst) check if lst[i]%2==0 newList.append(lst[i]) i=i+1…
Q: Write a function primeFac in Python that computes the prime factorization of a number: it accepts a…
A: The Python function to get the list of prime factors of a number greater than 1:Also I have checked…
Q: Write a function called safeAdd(d, k, v, unsafe=False) that takes either three or four input…
A: 1.in safe add function a. check if key is already in dict.keys() i. if unsafe is…
Q: Write a Python program that finds the largest value with its key from a given dictionary. [without…
A: Solution Logic Import package to find Maximum value in Dictionary create dictionary and…
Q: It returns how many times the number is found in the list. If the number is not in the list, return…
A: def how_many(a_list,a_num): count=0 #initializing count is zero for i in…
Q: Write a function randomList() that gets three integers as parameters, start, bound, and k. This…
A: In Python, to generate a list of random numbers with specified ranges and sizes, random.sample()…
Q: For this program, you have to write your own functions for lists without using any of the build-in…
A: Please find the answer below :
Q: Write a python program... Write a function called merge1(d1,d2) that takes two dictionaries as…
A: If you want to run the code you can run it on, online GDB compiler for python or you can run it on…
Q: Write a function littler_indices (integers, upper_limit) that returns a list of the indexes of every…
A: def littler_indices(integers, upper_limit): i_list = [] for i in range(0, len(integers)):…
Q: Given two dictionaries d1 and d2, write a function combine_dict(d1, d2), which return a new…
A: Python code to perform the rule for combine dictionary is given below, hope you like it.
Q: main.py 1 Fill in the blank in the function below with a single line of code, such that if pairs is…
A: upper() method converts all lowercase characters in a string into uppercase characters and returns…
Q: Write a function named create_names_dictionary (initials_list, names_list) which takes a list of…
A: Here I have defined the function named create_names_dictionary(). Next, I have used a loop to…
Q: Write a function that takes two arguments: stock and ingr (short for ingredients) and returns the…
A: In step 2, you will the python code.In step 3, you can see the sample output.
Q: Write a function lastDigits() that takes a list of numbers as parameter, returns a string made of…
A: The remainder of a number can be found using % operator and this is converted to string and appended…
Q: in python write a function where it makes a dictionary from given text file. If no value is present…
A: SUMMARY: - Hence, we discussed all the points.
Q: Write a function list2DigitOdd() that creates and returns a list that contain all positive 2-digit…
A: I have given an answer in step 2.
Q: Question: Write a Python program that takes a list of 10 numbers as input and generates a dictionary…
A: Algorithm:Before each iteration, if we tend to calculate position of the given range, then in a very…
Q: Instructions are given within the quotations for each function. 1)def remove_duplicate_sorted(t):…
A: t = [1, 3, 5, 6, 3, 5, 6, 1] print ("The original list is : " + str(t)) res = [] [res.append(x)…
Q: Write a program that reads in babynames.txt and produces two files, boynames.txt and girlnames.txt,…
A: # Create a bool variable to use as a flag. foundGirl = False # Get the search value from the…
Q: Write a python program... Write a function called merge2(d1,d2) that takes two dictionaries as…
A: Given: Write a python program... Write a function called merge2(d1,d2) that takes two dictionaries…
Q: Write a program in Python including the following functions: Write a function that takes a list and…
A: #to add in list recursivelydef addToLst(lst, value, times, index): #check if times need to add is…
Q: Write a program that takes a list of S integers and performs the following functions. Create two…
A: 1) Below is program that takes a list of S integers and performs delete prime and reverse list…
Q: Write a function is Prime (a_nNum) that takes a positive integer as an argument and returns True if…
A: Here is the python code. See below step for code and output:
Q: • Create a function which takes a tuple and returns a dictionary which is a histogram to count how…
A: I solve the question give the code along with screenshot of output along with histogram.
Q: Write a function called RemoveNum(numList) that takes a pre-defined list. Once the function is…
A: Use infinite loop to input value and break from loop when user entered 0
Q: Write the following function that merges two sorted lists into a new sorted list: void…
A: #include <bits/stdc++.h>#include<algorithm>using namespace std;int merge_arrays(int…
Q: Write a function that takes two arguments: stock and ingr (short for ingredients) and returns the…
A: The program loops through each item in stock for the required item i.e.for the first item in the…
Q: Please write it in Python Write a delete function that takes as an argument a list l and an elem…
A: Python Code: def delete( l, x ): l.remove(x) return x Explaination : Define a function…
Q: note: use python and not import Write a function named dictMax which takes two arguments: a…
A: For loop is used to iterate over list and each list item is compared against keys of a dictionary…
Q: Write a function that takes two arguments: stock and ingr (short for ingredients) and returns the…
A: Source code in Python: def checkStock(stock, ingr): result = [] for item, count in ingr: if…
Q: Python. Write a function letter_count(L) that takes a list of strings and returns a dictionary D…
A: D = dict() declare empty dictionary for string in L: for loop for traversing each string of…
Q: Write a function countRange() that takes three parameters, a list and two numbers, finds and returns…
A: I have given an answer in step 2.
Q: Create a program that will ask users to input names in a linked list. It should also allow users to…
A: Here I have created the node structure to store the data part and link to the next node. Next, I…
Q: Please answer it in Python Write a function min_pair that takes a list as an argument and returns…
A: '''logic to solve this problem:first extract all even numbers to a new list :Nthen traverse each…
Q: Write a function called find_duplicates which accepts one list as a parameter. This function…
A: In Python, lists are used to store multiple items in a single variable. Lists are mutable type its…
Q: Write a function remove_smallest() that gets a dictionary as a parameter and remove the item which…
A: Please find the answer below :
Q: Write a function randomList() that gets three integers as parameters, start, bound and k. This…
A: Given: Write a function randomList() that gets three integers as parameters, start, bound and k.…
Q: PYTHON CODE Write a function removeRange() that takes a list of integer numbers and two integer…
A: According to the Question below the Solution: Program Output:
PYTHON CODE - WRITE PYTHON FUNCTION
Step by step
Solved in 2 steps with 1 images
- In Python write a function that will play Rock, Paper, Scissors with itself. It will pick two random elements from a list. Then the function must know if random element #1 won, lost or drawed. The list is rps=[‘rock’, ‘paper’, ‘scissors’] Then the function must add to a dictionary the number of times the first element won per option in the list. Example{‘rock’:’400’, ‘paper’:’300’, ‘scissors’:’300’ } You need to run this at least 1000 times. You can either create a single thread, or you can create multiple threads. You need to use the random module and the random.choice(LISTNAME) to pick a random element from a list. Here's what I have so far: import random rps = ["rock", "paper", "scissors"] NumRock = 0 NumPaper = 0 NumScissors = 0 rand1 = random.choice(rps) rand2 = random.choice(rps) if rand1 == rand2: print("it's a tie") elif rand1 == "rock": if rand2 == "scissors": NumRock += 1…Python Write a function print_dict to print all the key-values in a dictionary, for example: >>> d2 {'a': 'one', 'b': 'two', 'c': 'Three'} >>> print_dict(d2) a:one b:two c:Threepython: def traditions_dict(adict): """ Question 6 Given a dictionary that maps a person to a list of their favorite traditions, return a dictionary with the value being the list sorted by the last letter of each tradition. If two traditions have the same last letter, sort by the first letter. HINT: This will require the use of lambda functions Args: adict (dict) Returns: dict >>> traditions_dict({"Jacob": ["The Horse", "Stealing the t", "Midnight Bud"], "Athena": ["Mini Five-Hundred", "Freshman Cake Race", "Buzzweiser Song"], "Liv": ["Freshman Cake Race", "George P. Burdell", "Buzzweiser Song"]}) {'Jacob': ['Midnight Bud', 'The Horse', 'Stealing the t'], 'Athena': ['Mini Five-Hundred', 'Freshman Cake Race', 'Buzzweiser Song'], 'Liv': ['Freshman Cake Race', 'Buzzweiser Song', 'George P. Burdell']} >>> traditions_dict({"Madison": ["The Horse", "Midnight Bud", "Buzzweiser…
- Write 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']…Write the code of the following functions: def fillX(pointsX,lowerLimit, upperLimit): This function receives a list pointsX and returns the same list with values between loverLimit and upperLimit. There are number of them.Question: 1 A Special Number is a number when the sum of the factorial of digits is equal to the original number (given number). For example, 145 is a Special Number because 145 = 1! + 4! + 5!. Your task is to write a Python code that takes some numbers as user inpt (separated by a comma) in a single line and groups the Special & Non-Special numbers in a dictionary. Note that the values corresponding to the keys in that dictionary must be in tuple format. Sample Input 1: 145, 346, 2, 83221, 7999888 Sample Output 1: {'Special: (145, 2), 'Non-Special': (346, 83221, 7999888 )} Sample Input 2: 1431, 69716, 353, 7969828 Sample Output 2: +. {'Special': (), 'Non-Special': (1431, 69716, 353, 7969828)}
- create a function in python parameters: 1. dict[str, list[str]] 2. list[str] return type: dict[str, list[str]] must do like this: 1. establish an empty dictionary that will serve as the dictionary returned at the end 2. loop thorugh each of the columns in the second parameter of the function 2a. asssign to the column key of the result dictionary the list of values stored in the input dictionary at the same column 3. return the dictionary produced do not import other libraries such as pandas, .select, .head, .iloc or anything this function is being used to work in a dataframetwo_sum is a Python function that takes in a list of integers (elements) and an integer number (num) and returns True if there exist two values in elements that add up to num, otherwise, function returns False. def two_sum(elements: List[int], num: int): for i in range(len(elements)): for j in range(i + 1): if elements[i] + elements[j] == num: return True return False Study above function and answer below questions: A. What is time complexity of two_sum? B. Is it possible to improve on above algorithm performance (in terms of its asymptotic cost)? If yes, describe your algorithm, be detailed as much as possible.Write a function named dictMax which takes two arguments: a dictionary and a list. Your function must look for the keys provided in the list argument, within the dictionary argument and return the maximum of the corresponding values. For example: dictMax({1:3, 3:2, 4:5, 2:6, 7:-1, 6:-3}, [3,2,6]) will return 6, because key 3 in the dictionary corresponds to value 2, key 2 to value 6 and key 6 to value -3, and among 2, 6 and -3, the maximum is 6. If a key does not exist in the dictionary, you should omit it. If none of the keys exist in the dictionary, you should return None.
- • Create a function which takes a tuple and returns a dictionary which is a histogramto count how many times each number exists in the tuple:• The main program must take the dictionary, transform the items into a list,use sort () to order the list (in ascending order) and after that display the list. def histo_n (x):'' '(tuple) -> dictReturns a dictionaryPrecondition: the tuple contains integers>>> t = (1,2, -3,3,4, -3,3,3)>>> histo_n (t){1: 1, 2: 1, 3: 3, 4: 1, -3: 2}'' ' Subject: Python ProgrammingIn Python use the Design Recipe to write a function count_evens_NxN, that consumes a nested list representing a matrix of size NxN. The function should return the number of even numbers in the matrix. For this function, 0 is considered an even number. Include a Docstring! Note: You may assume the list argument passed to the function is a nested list of integers Write 3 assert_equal statements to test your functionYou have been given the following lists of students and their test scores: names=['Joe','tom','bob','sue','sally'] Scores=[10,23,13,18,12]Write a function, makeDictionary , that takes the two lists and returns a dictionary with the names as the keys and the scores as thevalues. Assign the result of makeDictionary to scoreDict .calculate the average of all the scores in scoreDict in python.