Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50026

calculating binomial coefficients using itertools

Newsgroups comp.lang.python
Date 2013-07-05 15:58 -0700
Message-ID <5d22d723-bf1b-467d-b9d3-a9a814230309@googlegroups.com> (permalink)
Subject calculating binomial coefficients using itertools
From Robert Hunter <bobjim.hunter@gmail.com>

Show all headers | View raw


from itertools import count, repeat, izip, starmap

def binomial(n):
    """Calculate list of Nth-order binomial coefficients using itertools."""

    l = range(2)
    for _ in xrange(n):
        indices = izip(count(-1), count(1), repeat(1, len(l) + 1))
        slices = starmap(slice, indices)
        l = [sum(l[s]) for s in slices]
    return l[1:]

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

calculating binomial coefficients using itertools Robert Hunter <bobjim.hunter@gmail.com> - 2013-07-05 15:58 -0700
  Re: calculating binomial coefficients using itertools Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-06 01:11 -0600

csiph-web