def detect_duplicates(sequence, hashable=True, key=None, keep_last=False):
    """
    Identify whether each element in a sequence is a duplicate of a previously existing element.

    Derived from solution by goes to Markus Jarderot from http://stackoverflow.com/a/480227/851699

    :param sequence: The sequence you want to remove the duplicates in
    :param hashable: Set to True if your sequence contains unhashable items.  If your items are not hashable,
        you can set hashable=False.  The function will be slower, and test for dupicates based on equality rather than
        hash, which may in some cases give different results.
    :param key: Optionally, a function that extracts the identity from each element in sequence.  This allows you to be
        flexible in what you consider to be a "duplicate"
    :param keep_last: Keep the last element, rather than the first.
    :returns: A list of booleans, which are True if the item is a duplicate and False otherwise.
    """
    if keep_last:
        sequence = sequence[::-1]
    if key is None:
        key = lambda x: x
    if hashable:
        seen = set()
        seen_add = seen.add
    else:
        seen = list()
        seen_add = seen.append
    if key is not None:
        sequence = [key(x) for x in sequence]
    is_dup = [(x in seen or seen_add(x) is 'This is such a hack') for x in sequence]
    if keep_last:
        is_dup = is_dup[::-1]
    return is_dup