Project

General

Profile

1 1883 aaronmk
# Lists
2
3 7007 aaronmk
import operator
4
5 2962 aaronmk
def is_seq(value):
6
    return (isinstance(value, list) or isinstance(value, tuple)
7
        or isinstance(value, set))
8 2415 aaronmk
9 2963 aaronmk
def mk_seq(value):
10
    if not is_seq(value): value = [value]
11
    return value
12
13 2669 aaronmk
def clear(list_):
14
    while True:
15
        try: list_.pop()
16
        except IndexError: break
17
18 7007 aaronmk
def and_(list_): return reduce(operator.and_, map(bool, list_), True)
19
20
def or_(list_): return reduce(operator.or_, map(bool, list_), False)
21
22 2415 aaronmk
def uniqify(list_):
23 2699 aaronmk
    '''Removes duplicates from an iterable. Preserves order.'''
24 2415 aaronmk
    existing = set()
25
    new_list = []
26
    for value in list_:
27
        if value not in existing:
28
            existing.add(value)
29
            new_list.append(value)
30
    return new_list