Project

General

Profile

1
# Lists
2

    
3
import operator
4

    
5
def is_seq(value):
6
    return (isinstance(value, list) or isinstance(value, tuple)
7
        or isinstance(value, set))
8

    
9
def mk_seq(value):
10
    if not is_seq(value): value = [value]
11
    return value
12

    
13
def clear(list_):
14
    while True:
15
        try: list_.pop()
16
        except IndexError: break
17

    
18
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
def uniqify(list_):
23
    '''Removes duplicates from an iterable. Preserves order.'''
24
    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
(22-22/50)