diff options
author | Tim Hatch <tim@timhatch.com> | 2014-11-06 19:41:33 -0800 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2014-11-06 19:41:33 -0800 |
commit | 348b35f182e85f950e65a68d69d0f130912e8370 (patch) | |
tree | a527e8d5e04e9b5503bc88341135d1f916e29a9b /pygments/util.py | |
parent | c863ac19ce4d591b93be8b36cb69b04422c8dc9f (diff) | |
download | pygments-348b35f182e85f950e65a68d69d0f130912e8370.tar.gz |
Add 'duplicates_removed' function (for *_builtins.py generation).
Diffstat (limited to 'pygments/util.py')
-rw-r--r-- | pygments/util.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pygments/util.py b/pygments/util.py index 8376a67f..1f54c291 100644 --- a/pygments/util.py +++ b/pygments/util.py @@ -263,6 +263,22 @@ def format_lines(var_name, seq, raw=False, indent_level=0): return '\n'.join(lines) +def duplicates_removed(it, already_seen=()): + """ + Returns a list with duplicates removed from the iterable `it`. + + Order is preserved. + """ + lst = [] + seen = set() + for i in it: + if i in seen or i in already_seen: + continue + lst.append(i) + seen.add(i) + return lst + + class Future(object): """Generic class to defer some work. |