def index_of_dict_in_list(l, value, key=None):
    """Get index of item (a dict) in list

    # Example:
    ```python
    l = [
        {'a': 1},
        {'a': 2},
        {'a': 3}
    ]
    index_of_dict_in_list(l, 2) # returns 1
    ```
    """
    if key is None:
        for i, d in enumerate(l):
            v, = d.values()
            if v == value:
                return i
    else:
        for i, d in enumerate(l):
            if d[key] == value:
                return i
    raise ValueError('No value matched')
