def replace_many(s, d, inverse=False):
    """
    Goes through dict @d's keys and replaces their occurences with their 
    value. If @inverse is true, the values are replaced by the keys.
    NOTE: Results may vary from run to run and machine to machine because of 
    Python's dictionary optimization, especially if @inverse is true and some 
    keys have the same value. If a certain order is required, use a sorted 
    dictionary for @d. If @inverse is true, there may be no empty string 
    values, and if not, no empty string keys.

    >>> replace_many('quantum_junk10', {'1': '', '0': 'o', '_': ' '})
    'quantum junko'
    >>> replace_many('quantum_junk10', {'a': '0', 'b': '1'}, True)
    'quantum_junkba'
    >>> replace_many('quantum_junk10', {'': '5'})
    <TypeError traceback>

    AUTHORS:
    v0.2.0+             --> pydsigner
    """
    if inverse:
        for k in d:
            s = s.replace(d[k], k)
    else:
        for k in d:
            s = s.replace(k, d[k])
    return s
