uniq

ちょいとトリッキーなのと素朴で遅い奴。

def uniq(iterable):
    """
    >>> uniq([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9])
    [3, 1, 4, 5, 9, 2, 6, 8, 7]
    """
    s = set()
    return [s.add(i) or i for i in iterable if i not in s]

def uniq2(ls):
    """
    >>> uniq2([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9])
    [3, 1, 4, 5, 9, 2, 6, 8, 7]
    """
    return [ls[i] for i in xrange(len(ls)) if ls[i] not in ls[:i]]

def _test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    _test()