def generate_pattern(lvl, states, rewrite_rules):
    """
    Inputs:

    lvl
    -- integer number
    -- the number of times (iterations) rewrite rules will be applied

    states -- string, the initial state (axiom) of the system

    rewrite_rules
    -- dictionary
    -- keys (character) -> symbols
    -- values (string) -> replacement rules


    Returns string of symbols.
    """

    # In each iteration: check every character in states, replace valid symbol
    # with rewrite rule or copy character, and update states
    for _ in range(lvl + 1):
        states = ''.join([rewrite_rules.get(symbol, symbol) for symbol in states])

    # Clean states form rewrite rule flags/symbols
    drawing_rules = 'F+-'
    states = ''.join([symbol for symbol in states if symbol in drawing_rules])

    return states