Question

def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...

def count_evens(values: List[List[int]]) -> List[int]:
"""Return a list of counts of even numbers in each of the inner lists
of values.
  
>>> count_evens([[10, 20, 30]])
[3]
>>> count_evens([[1, 2], [3], [4, 5, 6]])
[1, 0, 2]
"""
  

Homework Answers

Answer #1

from typing import *


def count_evens(values: List[List[int]]) -> List[int]:
    """Return a list of counts of even numbers in each of the inner lists
    of values.

    >>> count_evens([[10, 20, 30]])
    [3]
    >>> count_evens([[1, 2], [3], [4, 5, 6]])
    [1, 0, 2]
    """
    counts = []
    for lst in values:
        count = 0
        for num in lst:
            if num % 2 == 0:
                count += 1
        counts.append(count)
    return counts


# Testing the function here. ignore/remove the code below if not required
print(count_evens([[10, 20, 30]]))
print(count_evens([[1, 2], [3], [4, 5, 6]]))


Know the answer?
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
Similar Questions
def is_even(value: int) -> bool: """Return True if and only if value is an even number....
def is_even(value: int) -> bool: """Return True if and only if value is an even number.    >>> is_even(108) True >>> is_even(135) False """ def convert_time(hour: int) -> int: """Return the given time in hours hour from the 24 hour clock to a time in hours for the 12 hour clock. Precondition: 0 <= hour <= 23 >>> convert_time(0) 12 >>> convert_time(4) 4 >>> convert_time(15) 3 """
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def...
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def label(tree): return tree[0] def branches(tree): return tree[1:] def is_tree(tree): if type(tree) != list or len(tree) < 1: return false return True def is_leaf(tree): return not branches(tree) def print_tree(t, indent=0):    print(' ' * indent + str(label(t))) for b in branches(t): print_tree(b, indent + 1) Write a function that takes in a tree and doubles every value. It should return a new tree. You can...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
create a function that takes a dictionary and returns a list of int. The list should...
create a function that takes a dictionary and returns a list of int. The list should appear in decreasing order based on the sum of number in each dictionary. def total_num(dict1): #Code here input = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':3}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} output = [1,5,3,4,2] 1: 38 2: 5 3: 8 4: 6 5: 15 1>5>3>4>2
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num == 0) return 0; else if (num > 100) return -1; else     return num + tq( num – 1 ); } Group of answer choices: 0 4 -1 10 Q2: Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)? int mystery(LLNode<Integer> list) {    if (list.getLink() ==...
LANGUAGE: SCHEME R5RS Create a procedure called preceeding that will take a list of numbers as...
LANGUAGE: SCHEME R5RS Create a procedure called preceeding that will take a list of numbers as argument and determine the elements and indices of those elements that preceed a negative number in the given list. The returned information should be in the form of a pair of lists: ((values) . (indices)). E.g. (preceeding '(1 -2 3 4 -5 6 -7 -8)) → ((1 4 6 -7).(0 3 5 6)) ;note: drracket will display this as ((1 4 6 -7) 0...
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                 {4, 5, 6} }; The following code below produces for (int row = numbers.length - 1; row >= 0; row -- ) { for (int col = 0; col < numbers[0].length; col ++) { System.out.print (numbers [row][col]); } }
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                 {4, 5, 6} }; The following code below produces for (int row = numbers.length - 1; row >= 0; row -- ) { for (int col = 0; col < numbers[0].length; col ++) { System.out.print (numbers [row][col]); } }
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)          ...
Consider the following two methods: public static boolean isTrue(int n){        if(n%2 == 0)           return true;        else           return false; } public static int Method(int[] numbers, int startIndex) { if(startIndex >= numbers.length)        return 0; if (isTrue(numbers[startIndex]))      return 1 + Method(numbers, startIndex + 1); else      return Method(numbers, startIndex + 1); } What is the final return value of Method() if it is called with the following parameters: numbers = {1, 2, 2, 3, 3,...
Write a function count_div5(nested_list) that takes in a list of lists of integers, and returns a...
Write a function count_div5(nested_list) that takes in a list of lists of integers, and returns a list of integers representing how many integers in each sublist of the original were divisible by 5. Examples: >>> count_div5([[5, 3, 25, 4], [46, 7], [5, 10, 15]]) [2, 0, 3] >>> count_div5([]) [] >>> count_div5([[-20, 10, 2, 4, 5], [], [5], [8, 25, 10], [6]]) [3, 0, 1, 2, 0]
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT