File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed
Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -204,23 +204,18 @@ def trace_msg(message, silent=False):
204204
205205
206206def nub (list_ ):
207- """Returns the unique items of a list of hashables, while preserving order of
208- the original list, i.e. the first unique element encoutered is
209- retained.
207+ """Returns the unique items of a list of hashables, while preserving order of the original list,
208+ i.e. the first unique element encoutered is retained.
210209
211- Code is taken from
212- http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order
210+ Code is taken from https://www.peterbe.com/plog/fastest-way-to-uniquify-a-list-in-python-3.6
213211
214- Supposedly, this is one of the fastest ways to determine the
215- unique elements of a list.
212+ Supposedly, this is one of the fastest ways to determine the unique elements of a list.
216213
217214 @type list_: a list :-)
218215
219216 :return: a new list with each element from `list` appearing only once (cfr. Michelle Dubois).
220217 """
221- seen = set ()
222- seen_add = seen .add
223- return [x for x in list_ if x not in seen and not seen_add (x )]
218+ return list (dict .fromkeys (list_ ))
224219
225220
226221def unique_ordered_extend (base , affix ):
You can’t perform that action at this time.
0 commit comments