5 queens
cf29
fcharlypillai at gmail.com
Mon Dec 24 03:18:29 EST 2007
On Dec 23, 2:04 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> def combinations(seq, n):
> if n == 0:
> yield []
> else:
> for i in xrange(len(seq)):
> for cc in combinations(seq[i+1:], n-1):
> yield [seq[i]]+cc
>
> >>> for c in combinations(range(4), 3):
>
> ... print c
> Steven
Thank you Steven, it works. I am so new to Python that I don't
understand fully how this function works to be able to adapt it to my
original problem. I wish I had a teacher :-)
Merry Xmas
More information about the Python-list
mailing list