def calculate_total(price_list: List[list]) -> int:
"""Return the sum of all second elements in the sublists of
price_list.
Precondition: price_list is a list of lists of length 2, and the
second
element of it sublist is an int.
>>> price_list = [["apple", 1], ["sugar", 5], ["mango",
3],
... ["coffee", 9], ["trail mix", 6]]
>>> calculate_total(price_list)
In this Python program
- We have defined a function called calculate_total which accepts a list and returns an int variable.
- In the list price_list, we have a list of lists which needs to satisfy 2 conditions one of them is it should have length 2 and also the 2nd element in the sublist should be an int
- Only those sublists which satisfy the above 2 conditions, those 2nd elements in the sublist got summed up
- Finally we are returning the int variable called sum as an output
Program:
def calculate_total(price_list: list) -> int:
sum=0
for i in price_list:
if( len(i)==2 and isinstance(i[1], int) ):
sum=sum+i[1]
return sum
price_list = [["apple", 1], ["sugar", 5], ["mango", 3],
["coffee", 9], ["trail mix", 6]]
print(calculate_total(price_list))
![main.py 1 def calculate_total(price_list: list) -> int: sum=0 for i in price_list: if( len(i)==2 and isinstance(i[1], int)):](http://img.homeworklib.com/questions/b3846b60-0b6e-11ec-a8b0-6d57303809c0.png?x-oss-process=image/resize,w_560)
Output:

Hope this answer is clear and Helps!!!
If not please comment, I will Help you with that...
def calculate_total(price_list: List[list]) -> int: """Return the sum of all second elements in the sublists of...
def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition: price_list is a list of lists in the following format: [ [str, int], [str, int], ... ] where each 2-element list represents a name (str) and a price (int) of an item. price_list has at least one element. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> most_expensive_item(price_list) """ please complete the function body in Python
def get_indices(lst, elm): ''' (list of lists, object) -> tuple of two ints Given a list of lists and an element, find the first pair of indices at which that element is found and return this as a tuple of two ints. The first int would be the index of the sublist where the element occurs, and the second int would be the index within this sublist where it occurs. >>> get_indices([[1, 3, 4], [5, 6, 7]], 1) (0, 0)...
def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in order. Each slice is a list of size <n> containing the next <n> elements in <lst>. The last slice may contain fewer than <n> elements in order to make sure that the returned list contains all elements in <lst>. === Precondition === n <= len(lst) >>> slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] True >>> slice_list(['a', 1, 6.0, False],...
I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on) with comments: import java.util.ArrayList; public class Mergesort { /** * Sorts list given using the mergesort algorithm * @param list the list to be sorted * @param first the index of the first element of the list to be sorted * @param last the index of the last element of the list to be sorted */ public static void mergesort(ArrayList<Comparable> list, int first, int...
def _merge(lst: list, start: int, mid: int, end: int) -> None: """Sort the items in lst[start:end] in non-decreasing order. Precondition: lst[start:mid] and lst[mid:end] are sorted. """ result = [] left = start right = mid while left < mid and right < end: if lst[left] < lst[right]: result.append(lst[left]) left += 1 else: result.append(lst[right]) right += 1 # This replaces lst[start:end] with the correct sorted version. lst[start:end] = result + lst[left:mid] + lst[right:end] def find_runs(lst: list) -> List[Tuple[int, int]]: """Return a...
C++ Programming Code Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include <iostream> #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList<int> list, subList; int num; cout << "Enter...
In this assignment, you will use a Hashtable to determine the
common elements in all the lists. If an element appears more than
once in one or more lists, the algorithm should capture the
instances the element is present in all the lists.
You are given a code that implements a Hashtable as an array of
linked lists. You are also given a main function that will create
an array of Lists using the input variable values that you enter....
def verifyMagic( matrix, num): "!" Given a list of lists called matrix, recursively verify that each list sums to num. Return True if that's the case, otherwise, return false. If the list is empty, return None. Assume that the correct input types were given." # Base case 1: a matrix with no elements if return # Base case 2: a matrix with one element if # Check if the sum of the only element in the list is num. #...
#C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't add the these two file.(unorderedlinked.h and linkedlist.h) as well as the output Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList list, subList; int num; ...