def get_at(doc, path, create_anyway=False):
    """Get the value, if any, of the document at the given path, optionally
        mutating the document to create nested dictionaries as necessary.
        """
    node = doc
    last = len(path) - 1
    if last == 0:
        return doc.get(path[0])
    for index, edge in enumerate(path):
        if edge in node:
            node = node[edge]
        elif index == last or not create_anyway:
            # the key doesn't exist, and this is the end of the path:
            return None
        else:
            # create anyway will create any missing nodes:
            node = node[edge] = {}
    return node