diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-07-15 16:02:55 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-07-15 16:02:55 +0200 |
commit | f8e0412210772db73786dcd4e0cf94479758194a (patch) | |
tree | c4d101709b2208eb1ac87e09572bab59c3d0b52e /module/utils.py | |
parent | Added missing shebangs, removed unnecessary ones (diff) | |
download | pyload-f8e0412210772db73786dcd4e0cf94479758194a.tar.xz |
Improved uniqify method
Diffstat (limited to 'module/utils.py')
-rw-r--r-- | module/utils.py | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/module/utils.py b/module/utils.py index 424aeaf37..fa6b84095 100644 --- a/module/utils.py +++ b/module/utils.py @@ -136,21 +136,11 @@ def fs_bsize(path): return os.statvfs(path).f_bsize -def uniqify(seq, idfun=None): -# order preserving - if idfun is None: - def idfun(x): return x - seen = {} - result = [] - for item in seq: - marker = idfun(item) - # in old Python versions: - # if seen.has_key(marker) - # but in new ones: - if marker in seen: continue - seen[marker] = 1 - result.append(item) - return result +def uniqify(seq): #: Originally by Dave Kirby + """ removes duplicates from list, preserve order """ + seen = set() + seen_add = seen.add + return [x for x in seq if x not in seen and not seen_add(x)] def parseFileSize(string, unit=None): #returns bytes |