import itertools


def create_possible_expected_messages(message_template, expected_types):
    """
    Some error messages contain dictionaries with error types. Dictionaries
    in Python are unordered so it makes testing unpredictable. This
    function takes in a message template and a list of types and returns
    a list that contains error messages for every permutation of the types.

    Args:
        message_template (str): A string with a single format argument ({}).
        expected_types (list): A list of types. Ex: [str, int]
    Returns:
        list: A list of the given error message formatted with all permutations
              of the given type list.
    """
    # Create an iterable of all the permutations of the types.
    # Can roughly be thought of as a list of tuples
    type_premutations = itertools.permutations(expected_types)

    # For each permutation, map each type in the permutation to a string
    # and remove '<' and '>' since this is how our exceptions format them.
    formatted_string_types = [
        map(lambda s: str(s).replace('<', '').replace('>', ''), t)
        for t in type_premutations
    ]

    # Finally, create an error message with each permutation.
    return [
        message_template.format(', '.join(f)) for f in formatted_string_types
    ]