예제 #1
0
def concat(xss):
    """
    >>> concat([[]])
    []
    >>> concat((()))
    []
    >>> concat([[1,2,3],[4,5]])
    [1, 2, 3, 4, 5]
    >>> concat([[1,2,3],[4,5,[6,7]]])
    [1, 2, 3, 4, 5, [6, 7]]
    >>> concat(((1,2,3),(4,5,[6,7])))
    [1, 2, 3, 4, 5, [6, 7]]
    >>> concat(((1,2,3),(4,5,[6,7])))
    [1, 2, 3, 4, 5, [6, 7]]
    >>> concat((i, i*2) for i in range(3))
    [0, 0, 1, 2, 2, 4]
    """
    return foldl(listplus, (xs for xs in xss), [])
예제 #2
0
파일: index.py 프로젝트: tkbctf/tkbctf4
def shuffle2():
    room = Room(request.environ.get('beaker.session'))

    mask, c0, c1, c1_k = [room.get(x) for x in ['mask', 'c0', 'c1', 'c1_k']]

    d = json.loads(request.forms.get('q'))

    def f(i):
        r, pi = map(lambda x : jsonToInteger(x), d[i][0]), d[i][1]

        if all(toInt(x) % 2 != 0 for x in r):
            return procedure_33(c1, c1_k[i], r, pi) if mask[i] else procedure_33(c0, c1_k[i], r, pi)
        else:
            return False

    if not all( f(i) for i in range(numbers['s']) ):
        fail()
        return 'fail to verify c1'

    room.state('shuffle3');

    ci, ri, pii = procedure_32(c1, room.group)

    room.set('ci', ci)
    room.set('ri', ri)
    room.set('pii', pii)

    c_ik = [ procedure_32(ci, room.group) for _ in range(numbers['s']) ]
    
    room.set('c_ik', c_ik)

    room.save()

    response.content_type = 'application/json'
    return json.dumps(map(toStr, {
        'c_i'  : ci,
        'c_ik' : foldl(lambda x, y: x + [y[0]], c_ik, [])
        }))
예제 #3
0
def _flatten(xss):
    """
    >>> _flatten([])
    []
    >>> _flatten([[1,2,3],[4,5]])
    [1, 2, 3, 4, 5]
    >>> _flatten([[1,2,[3]],[4,[5,6]]])
    [1, 2, 3, 4, 5, 6]

    tuple:

    >>> _flatten([(1,2,3),(4,5)])
    [1, 2, 3, 4, 5]

    generator expression:

    >>> _flatten((i, i * 2) for i in range(0,5))
    [0, 0, 1, 2, 2, 4, 3, 6, 4, 8]
    """
    if is_foldable(xss):
        return foldl(operator.add, (_flatten(xs) for xs in xss), [])
    else:
        return [xss]
예제 #4
0
파일: utils.py 프로젝트: ssato/rpmkit
def _flatten(xss):
    """
    >>> _flatten([])
    []
    >>> _flatten([[1,2,3],[4,5]])
    [1, 2, 3, 4, 5]
    >>> _flatten([[1,2,[3]],[4,[5,6]]])
    [1, 2, 3, 4, 5, 6]

    tuple:

    >>> _flatten([(1,2,3),(4,5)])
    [1, 2, 3, 4, 5]

    generator expression:

    >>> _flatten((i, i * 2) for i in range(0,5))
    [0, 0, 1, 2, 2, 4, 3, 6, 4, 8]
    """
    if is_foldable(xss):
        return foldl(operator.add, (_flatten(xs) for xs in xss), [])
    else:
        return [xss]
예제 #5
0
def find_vars(filepath, paths):
    return jinja2_cli.utils.uniq(foldl(listplus,
                                       (vs[1] for vs in find_vars_0(filepath,
                                                                    paths)),
                                       []))
예제 #6
0
파일: util.py 프로젝트: pillmuncher/hornet
def rfoldr(func, seq, start=_sentinel):
    if start is _sentinel:
        return foldl(func, reversed(seq))
    return foldl(func, reversed(seq), start)
예제 #7
0
파일: util.py 프로젝트: pillmuncher/hornet
def rfoldl(func, seq, start=_sentinel):
    if start is _sentinel:
        return foldl(flip(func), seq)
    return foldl(flip(func), seq, start)
def compose(*functions):
    """Compose an iterable of one-argument functions."""
    def compose2(f, g):
        return lambda x: f(g(x))

    return foldl(compose2, functions, lambda x: x)  # op(acc, elt)
def reverse(ll):
    """Reverse a linked list."""
    return foldl(snoc, ll, nil)
예제 #10
0
def foldr(function, sequence, initial=None):
    """Right fold."""
    return foldl(function, reversed(sequence), initial)