Write a function which outputs the positions of matching bracket pairs. The output should be a dictionary with keys the positions of the open brackets '(' and values the corresponding positions of the closing brackets ')'.
For example: input = "(first)and(second)" should return {0:6, 10:17}
If brackets cannot be paired or if the order is invalid (e.g. ')(') return False. In this kata we care only about the positions of round brackets '()', other types of brackets should be ignored.
def bracket_pairs(string):
    ob, res = [], {}
    
    for n,e in enumerate(string):
        if e == '(':
            ob.append(n)
        elif e == ')':
            if not ob:
                return False
            res[ob.pop()] = n
    return False if ob else res
def bracket_pairs(string):
    ob, res = [], {}
    
    for n,e in enumerate(string):
        if e == '(':
            ob.append(n)
        elif e == ')':
            if not ob:
                return False
            res[ob.pop()] = n
    return False if ob else res