A simple problem really, but since I had to look for it I figured I would post it up. I actually got this from Peter Bengtsson’s blog, since he had run some benchmarks on speed.

At any rate, I kept the order preserving one since I like things in order to keep my life simple.

def uniq(inlist): 
    # order preserving
    uniques = []
    for item in inlist:
        if item not in uniques:
    return uniques

I put this in a unique.py in my ~/library/python directory (which is in my PYTHONPATH) and now I can pull this into scripts with:

from unique import uniq

Technorati Tags: