src/ztfy/utils/list.py
branchZTK-1.1
changeset 163 d07844bfe41d
equal deleted inserted replaced
162:2537855e0f97 163:d07844bfe41d
       
     1 ### -*- coding: utf-8 -*- ####################################################
       
     2 ##############################################################################
       
     3 #
       
     4 # Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
       
     5 # All Rights Reserved.
       
     6 #
       
     7 # This software is subject to the provisions of the Zope Public License,
       
     8 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
    10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    12 # FOR A PARTICULAR PURPOSE.
       
    13 #
       
    14 ##############################################################################
       
    15 
       
    16 
       
    17 # import standard packages
       
    18 
       
    19 # import Zope3 interfaces
       
    20 
       
    21 # import local interfaces
       
    22 
       
    23 # import Zope3 packages
       
    24 
       
    25 # import local packages
       
    26 
       
    27 
       
    28 def unique(seq, idfun=None):
       
    29     """Get list unique values, preserving order"""
       
    30     if idfun is None:
       
    31         def idfun(x): return x
       
    32     seen = {}
       
    33     result = []
       
    34     for item in seq:
       
    35         marker = idfun(item)
       
    36         if marker in seen:
       
    37             continue
       
    38         seen[marker] = 1
       
    39         result.append(item)
       
    40     return result