import re
from functools import reduce
import operator


def get_value(key, dictionary):
    """ Returns a value from a dictionary given a key using dot and bracket
        notation. eg: a possible key could be 'user.posts[1].comments[2]'.

    Parameters:
    key (str)        : the key to be used to retrieve its corresponding value from
                       the dictionary.
    dictionary (dict): the dictionary were that value is extracted from using the
                       key above.

    Returns:
    int/float/str/list/dict/bool/None: Returning value

    """
    try:
        # We're using 2 regular expressions, the first one to try to cast the value as int if
        # possible, the second one to convert the key using dot and bracket notation into a list
        # of ordered keys to access the value in the dictionary.
        keys = [int(k) if re.match(r'^\d+$', k) else k for k in re.findall(r'[^\[^\]^\.]+', key)]
        # Reduce is here used to access any value in the dictionary using a list of keys of 
        # arbitrary length.
        return reduce(operator.getitem, keys, dictionary)
    # If a particular key is invalid (which is to be expected), None is returned.
    except (KeyError, IndexError, TypeError):
        return None