root/lib/lists.py @ 2874
1 |
# Lists
|
---|---|
2 |
|
3 |
def is_seq(value): return isinstance(value, list) or isinstance(value, tuple) |
4 |
|
5 |
def clear(list_): |
6 |
while True: |
7 |
try: list_.pop() |
8 |
except IndexError: break |
9 |
|
10 |
def uniqify(list_): |
11 |
'''Removes duplicates from an iterable. Preserves order.'''
|
12 |
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 |