def uniq_stable(elems):
unique = []<EOL>unique_dict = {}<EOL>for nn in elems:<EOL><INDENT>if nn not in unique_dict:<EOL><INDENT>unique.append(nn)<EOL>unique_dict[nn] = None<EOL><DEDENT><DEDENT>return unique<EOL>
uniq_stable(elems) -> list

    Return from an iterable, a list of all the unique elements in the input,
    but maintaining the order in which they first appear.

    A naive solution to this problem which just makes a dictionary with the
    elements as keys fails to respect the stability condition, since
    dictionaries are unsorted by nature.

    Note: All elements in the input must be valid dictionary keys for this
    routine to work, as it internally uses a dictionary for efficiency
    reasons.