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