##// END OF EJS Templates
utils.data: Use list comprehension for uniq_stable()...
W. Trevor King -
Show More
@@ -25,21 +25,11 b' def uniq_stable(elems):'
25 Return from an iterable, a list of all the unique elements in the input,
25 Return from an iterable, a list of all the unique elements in the input,
26 but maintaining the order in which they first appear.
26 but maintaining the order in which they first appear.
27
27
28 A naive solution to this problem which just makes a dictionary with the
28 Note: All elements in the input must be hashable for this routine
29 elements as keys fails to respect the stability condition, since
29 to work, as it internally uses a set for efficiency reasons.
30 dictionaries are unsorted by nature.
30 """
31
31 seen = set()
32 Note: All elements in the input must be valid dictionary keys for this
32 return [x for x in elems if x not in seen and not seen.add(x)]
33 routine to work, as it internally uses a dictionary for efficiency
34 reasons."""
35
36 unique = []
37 unique_dict = {}
38 for nn in elems:
39 if nn not in unique_dict:
40 unique.append(nn)
41 unique_dict[nn] = None
42 return unique
43
33
44
34
45 def sort_compare(lst1, lst2, inplace=1):
35 def sort_compare(lst1, lst2, inplace=1):
General Comments 0
You need to be logged in to leave comments. Login now