from typing import Union


def all_keys(d: Union[dict, list]) -> list:
    """
    Returns a list of all the keys of a dictionary (duplicates included)
    d -- a dictionary to iterate through
    """

    if not d:
        return []

    if d is None or not isinstance(d, dict) and not isinstance(d, list):
        return []

    keys = []

    if isinstance(d, list):
        for entry in d:
            keys.extend(all_keys(entry))
    else:
        for k, v in d.items():
            keys.append(k)
            keys.extend(all_keys(v))

    return keys