root/lib/lists.py @ 2938
1 | 1883 | aaronmk | # Lists
|
---|---|---|---|
2 | |||
3 | def is_seq(value): return isinstance(value, list) or isinstance(value, tuple) |
||
4 | 2415 | aaronmk | |
5 | 2669 | aaronmk | def clear(list_): |
6 | while True: |
||
7 | try: list_.pop() |
||
8 | except IndexError: break |
||
9 | |||
10 | 2415 | aaronmk | def uniqify(list_): |
11 | 2699 | aaronmk | '''Removes duplicates from an iterable. Preserves order.'''
|
12 | 2415 | aaronmk | existing = set() |
13 | new_list = [] |
||
14 | for value in list_: |
||
15 | if value not in existing: |
||
16 | existing.add(value) |
||
17 | new_list.append(value) |
||
18 | return new_list |