solutions

Dict to Tuple

Create a function dict_to_tuple that receives a dictionary and returns a list of tuples containing the key-value pairs. Example:

dict_to_tuple({'a': 1, 'b': 2})  # [('a', 1), ('b', 2)]
dict_to_tuple({'Hello': 'World'})  # [('Hello', 'World')]

Test Cases

test empty dict - Run Test

def test_empty_dict():
    assert dict_to_tuple({}) == []

test one item dict - Run Test

def test_one_item_dict():
    result = dict_to_tuple({'my_key': 20})
    expected = [('my_key', 20)]
    assert result == expected

test with many items - Run Test

def test_with_many_items():
    result = dict_to_tuple({'Z': 3, 'X': 2, 'Y': 1})
    expected = [('Z', 3), ('X', 2), ('Y', 1)]
    assert sorted(result) == sorted(expected)