import re


def replace(instring, indict):
    """
    This function provides a simple but effective template system for your html 
    pages. Effectively it is a convenient way of doing multiple replaces in a 
    single string.
    
    Takes a string and a dictionary of replacements. 
    
    This function goes through the string and replaces every occurrence of every 
    dicitionary key with it's value.
    
    ``indict`` can also be a list of tuples instead of a dictionary (or anything 
    accepted by the dict function).
    """
    indict = dict(indict)
    if len(indict) > 40:
        regex = re.compile("(%s)" % "|".join(map(re.escape, indict.keys())))
        # For each match, look-up corresponding value in dictionary
        return regex.sub(lambda mo: indict[mo.string[mo.start():mo.end()]],
                                                                    instring)
    for key in indict:
        instring = instring.replace(key, indict[key])
    return instring