from typing import Dict
from typing import Any
from typing import Iterator
from typing import Tuple


def flatten(dictionary: Dict[str, Any]) -> Dict[str, Any]:
    """
    >>> flatten({'foo':{'bar':{'baz': 0}, 'deadbeef': 1}, '42': 3})
    {'foo.bar.baz': 0, 'foo.deadbeef': 1, '42': 3}
    """
    def iterate(data: Dict[str, Any], prefix: str) -> Iterator[Tuple[str, Any]]:
        for key, value in data.items():
            prefixed_key = prefix + key
            if isinstance(value, dict):
                for prefixed_subkey, val in iterate(value, prefixed_key + '.'):
                    yield prefixed_subkey, val
            else:
                yield prefixed_key, value

    return dict(iterate(dictionary, ""))