Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:code': 0.07; 'compute': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '136,': 0.16; '161,': 0.16; '5)]': 0.16; '55,': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'subject:combinations': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'written': 0.19; 'subject:list': 0.21; 'from:addr:web.de': 0.23; 'code': 0.26; 'example': 0.29; 'thanks': 0.32; 'list': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints- To:1': 0.34; 'someone': 0.34; 'skip:i 40': 0.34; 'to:addr:python- list': 0.35; 'list.': 0.35; 'list:': 0.35; 'received:org': 0.36; 'should': 0.38; 'to:addr:python.org': 0.40; 'your': 0.61; 'wishes': 0.64; '29,': 0.73; 'subject: ': 0.74; '128,': 0.84; 'subject:printing': 0.84; 'numbers:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: code for computing and printing list of combinations Date: Tue, 20 Mar 2012 16:20:32 +0100 Organization: None References: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849737.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332256833 news.xs4all.nl 6903 [2001:888:2000:d::a6]:51619 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21932 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...