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]
    """
    even_counts = []
    for value_list in values:
        count = 0
        for n in value_list:
            if n % 2 == 0:
                count += 1
        even_counts.append(count)
    return even_counts
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 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] """   
def max_length(obj: Union[int, List]) -> int: """Return the maximum length of any list in nested list...
def max_length(obj: Union[int, List]) -> int: """Return the maximum length of any list in nested list <obj>. The *maximum length* of a nested list is defined as: 1. 0, if <obj> is a number. 2. The maximum of len(obj) and the lengths of the nested lists contained in <obj>, if <obj> is a list. >>> max_length(17) 0 >>> max_length([1, 2, [1, 2], 4]) 4 >>> max_length([1, 2, [1, 2, [3], 4, 5], 4]) 5 """ pass
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return...
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return the length of the longest chain of 1's that start from the beginning. You MUST use a while loop for this! We will check. >>> longest_chain([1, 1, 0]) 2 >>> longest_chain([0, 1, 1]) 0 >>> longest_chain([1, 0, 1]) 1 """ i = 0 a = [] while i < len(submatrix) and submatrix[i] != 0: a.append(submatrix[i]) i += 1 return sum(a) def largest_rectangle_at_position(matrix: List[List[int]], x:...
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...
def count_pairs(num_list): Given a list of numbers num_list, count how many ways unique pairs of values...
def count_pairs(num_list): Given a list of numbers num_list, count how many ways unique pairs of values from this list have a sum equal to a value anywhere in the list (including equaling one of the values being added). Watch out for duplicates – two locations may sum up to a value equal to many places in the list, but they only count as one pairing overall. The two summed values must be at unique locations in the list. • Parameters:...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most factors (divisors without remainder). For example: >>> most_factors([5,10,16,20,25]) 20 # because 20 has the most factors of any of these numbers # 6 factors, i.e., [1, 2, 4, 5, 10, 20] >>> most_factors([1, 2, 3, 4, 5]) 4 # because 4 has the most factors of any of these numbers # 3 factors, i.e., [1, 2, 4] Hints: For each element in numbers, call...
# Python Given the list values = [], write code that fills the list with each...
# Python Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0...
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