[Numpy-discussion] Picking rows with the first (or last) occurrence of each key

Alan Isaac alan.isaac at gmail.com
Sun Jul 3 10:13:18 EDT 2016

1. This is not a NumPy question; StackExchange would be more appropriate.
2. Do some bookkeeping:

def initialKeyFilter(data, length, invert=False):
     result = list()
     seen = set()
     if invert:
         data = reversed(data)
     for datum in data:
         k = tuple(datum[:length])
         if (k not in seen):
     if invert: result.reverse()
     return result

Alan Isaac

More information about the NumPy-Discussion mailing list