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


Groups > comp.lang.python > #21932

Re: code for computing and printing list of combinations

From Peter Otten <__peter__@web.de>
Subject Re: code for computing and printing list of combinations
Date 2012-03-20 16:20 +0100
Organization None
References <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com>
Newsgroups comp.lang.python
Message-ID <mailman.831.1332256833.3037.python-list@python.org> (permalink)

Show all headers | View raw


Joi Mond wrote:

> Can someone help me with the proper code to compute combinations for n=7,
> r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There
> should be 21 combination. Also once there list is made can a code be
> written to add (sum) each of the set of five number in the the list. For
> example list: 8, 10, 29, 48, 55, = 150. Thanks

>>> [sum(x) for x in itertools.combinations([7,8,10,29,41,48,55], 5)]
[95, 102, 109, 114, 121, 128, 133, 140, 147, 159, 135, 142, 149, 161, 180, 
136, 143, 150, 162, 181, 183]

Best wishes to your teacher...

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


Thread

Re: code for computing  and printing list of combinations Peter Otten <__peter__@web.de> - 2012-03-20 16:20 +0100

csiph-web