The list.append method returns None . So y = y.append(n) sets y to None .
If this happens on the most recent iteration of the for-loop , None returned.
If this happens before the last iteration, then the next time through a loop
if n not in y
will raise
TypeError: argument of type 'NoneType' is not iterable
Note. In most cases, there are faster ways to remove duplicates than method 1, but how to do this depends on whether you want to maintain order if the elements are ordered, and if the elements in x are hashed.
def unique_hashable(seq):
And this may be the fastest if you have NumPy, and elements in seq can be ordered:
import numpy as np def unique_order_preserving_numpy(seq): u, ind = np.unique(seq, return_index=True) return u[np.argsort(ind)]
source share