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


Groups > comp.lang.python > #21932 > unrolled thread

Re: code for computing and printing list of combinations

Started byPeter Otten <__peter__@web.de>
First post2012-03-20 16:20 +0100
Last post2012-03-20 16:20 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#21932 — Re: code for computing and printing list of combinations

FromPeter Otten <__peter__@web.de>
Date2012-03-20 16:20 +0100
SubjectRe: code for computing and printing list of combinations
Message-ID<mailman.831.1332256833.3037.python-list@python.org>
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...

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web