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