def parseColorLine(ls, keys, flags=set()):
    """
    >>> parseColorLine("CODE 0 VALUE #05131D FOO".split(), {"CODE", "VALUE", "EDGE", "BAR"})
    ({'CODE': '0', 'VALUE': '#05131D'}, set())
    """
    d = {}
    s = set()
    for idx, val in enumerate(ls):
        if val in keys and idx+1 < len(ls):
            d[val] = ls[idx+1]
        elif val in flags:
            s.add(val)
    return d, s