/usr/share/pyshared/enthought/util/sequence.py is in python-enthoughtbase 3.1.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 'Non-standard functions for various sequence objects'
###############################################################################
# sequence objects
###############################################################################
def is_sequence(x):
try:
iter(x)
return True
except TypeError:
return False
all = lambda l: False not in map(bool, l)
any = lambda l: True in map(bool, l)
###############################################################################
# list
###############################################################################
def concat(lists):
''' Concatenate a list of lists.
>>> concat(range(i) for i in range(5))
[0, 0, 1, 0, 1, 2, 0, 1, 2, 3]
>>> concat([[1,2], [3]])
[1, 2, 3]
>>> concat([[1,2,[3,4]], [5,6]])
[1, 2, [3, 4], 5, 6]
>>> concat([])
[]
'''
l = []
map(l.extend, lists)
return l
###############################################################################
# set
###############################################################################
from copy import copy
def union(sets):
''' Union a collection of sets.
>>> union([set('ab'), set('bc'), set('ac')]) == set('abc')
True
>>> union([])
set([])
'''
s = set()
map(s.update, sets)
return s
def intersect(sets):
''' Intersect a non-empty collection of sets.
>>> intersect([set('ab'), set('bc'), set('bb')])
set(['b'])
>>> intersect([set('ab'), set('bc'), set('ac')])
set([])
>>> try: intersect([])
... except: print 'bad'
...
bad
'''
sets = iter(sets)
s = copy(sets.next())
map(s.intersection_update, sets)
return s
def disjoint(*sets):
''' Test whether a collection of sets is pair-wise disjoint.
>>> disjoint(set([1,2]), set([3]))
True
>>> disjoint(set('abc'), set('xy'), set('z'), set('cde'))
False
>>> disjoint()
True
'''
return len(union(sets)) == len(concat(sets))
|