# HG changeset patch # User Thierry Florac # Date 1345212801 -7200 # Node ID d07844bfe41deb9200266df3c887882bf50204b2 # Parent 2537855e0f97471c7769f8f4631fd16dfdd9787a Added lists utility module diff -r 2537855e0f97 -r d07844bfe41d src/ztfy/utils/list.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ztfy/utils/list.py Fri Aug 17 16:13:21 2012 +0200 @@ -0,0 +1,40 @@ +### -*- coding: utf-8 -*- #################################################### +############################################################################## +# +# Copyright (c) 2012 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## + + +# import standard packages + +# import Zope3 interfaces + +# import local interfaces + +# import Zope3 packages + +# import local packages + + +def unique(seq, idfun=None): + """Get list unique values, preserving order""" + if idfun is None: + def idfun(x): return x + seen = {} + result = [] + for item in seq: + marker = idfun(item) + if marker in seen: + continue + seen[marker] = 1 + result.append(item) + return result