from typing import Union
from typing import List
from typing import Tuple
from typing import Dict


def format_locations(locations: Union[str, List, Tuple]) -> List[Dict[str, str]]:
    """
    Format locations from YAML file into the list format expected by boto3.

    Possible inputs are:
      a) A 2 letter country code string, e.g. "US"
      b) A 2-tuple (or 2 item list) of 2 letter country and subdivision codes , e.g ("US", "NY")
      c) A list of two or more instances of a) and/or b)
    """
    if isinstance(locations, str):
        return [{'Country': locations}]
    elif isinstance(locations, list) or isinstance(locations, tuple):
        return [{'Country': l[0], 'Subdivision': l[1]} if isinstance(l, (tuple, list))
             else {'Country': l} for l in locations]
    else:
        raise TypeError