diff --git a/IPython/utils/data.py b/IPython/utils/data.py index 2b7a404..69811d9 100644 --- a/IPython/utils/data.py +++ b/IPython/utils/data.py @@ -25,21 +25,11 @@ def uniq_stable(elems): 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.""" - - unique = [] - unique_dict = {} - for nn in elems: - if nn not in unique_dict: - unique.append(nn) - unique_dict[nn] = None - return unique + Note: All elements in the input must be hashable for this routine + to work, as it internally uses a set for efficiency reasons. + """ + seen = set() + return [x for x in elems if x not in seen and not seen.add(x)] def sort_compare(lst1, lst2, inplace=1):