Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'talks': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'problem?': 0.07; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'language.': 0.14; 'iterating': 0.16; 'manageable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:generation': 0.16; 'elements': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; '>>>': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'now?': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'url:mailman': 0.30; 'code': 0.31; 'usually': 0.31; 'about.': 0.31; 'url:python': 0.33; 'fri,': 0.33; 'guess': 0.33; 'programmers': 0.33; 'actual': 0.34; 'could': 0.34; 'something': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'extremely': 0.39; 'generating': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'even': 0.60; 'hope': 0.61; 'mentioned': 0.61; 'simply': 0.61; "you're": 0.61; 'our': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'mar': 0.68; '100': 0.79; 'age': 0.80; '2015': 0.84; 'itertools,': 0.84; 'measure.': 0.84; 'hundred': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Speeding up permutations generation Date: Fri, 06 Mar 2015 10:33:01 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-2-240.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425637998 news.xs4all.nl 2858 [2001:888:2000:d::a6]:44631 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87013 On 06/03/2015 09:59, Chris Angelico wrote: > On Fri, Mar 6, 2015 at 7:24 PM, Abhiram R wrote: >>> A list of 100 elements has approximately 9.33 x 10**157 permutations. >>> If you could somehow generate one permutation every yoctosecond, >>> exhausting them would still take more than a hundred orders of >>> magnitude longer than the age of the universe. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >> >> True that :D I may have exaggerated on the number. Let's consider something >> more practically manageable => 50 elements with a 50! permutation. >> Is there a solution now? >> > > Is the actual generation of permutations your problem? You mentioned > that you're using itertools, so I would expect that you're simply > iterating over that; I hope you're not immediately trying to construct > a list of them all, because that would cost the memory that Mark's > response talks about. Have you actually profiled your code and found > that generating permutations is the bottleneck, or did you just guess? > Because even experienced programmers - even extremely experienced > Python programmers - are usually wrong when they guess about the > slowest part of a program. The only way to know is to measure. > > ChrisA > s/Mark/Wolfgang/ ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence