Solution 1

def init_dict(a_list):
    return {k: 0 for k in a_list}

Dictionary Comprehension

Write a function that receives a list and
returns a dictionary with the elements initialized with the value 0.

You MUST use dict comprehensions.

Example:

init_dict(['a', 'b', 'c']) # {'a': 0, 'b': 0, 'c': 0}

Test Cases

test two keys - Run Test

def test_two_keys():
    assert init_dict(['a', 'b']) == {'a': 0, 'b': 0}

test empty list - Run Test

def test_empty_list():
    assert init_dict([]) == {}

test three keys - Run Test

def test_three_keys():
    assert init_dict(['a', 'b', 'c']) == {'a': 0, 'b': 0, 'c': 0} 

test integer keys - Run Test

def test_integer_keys():
    assert init_dict([1, 2, 3]) == {1: 0, 2: 0, 3: 0} 
def init_dict(a_list): pass