Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!news2.euro.net!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'list...': 0.07; 'lst': 0.09; 'python': 0.11; 'def': 0.12; "('b',": 0.16; "('c',": 0.16; '-tkc': 0.16; "[('a',": 0.16; 'from:name:tim chase': 0.16; 'itertools': 0.16; ':-)': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'skip:l 30': 0.24; 'sort': 0.25; 'define': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'list:': 0.30; 'asks': 0.31; "d'aprano": 0.31; 'int,': 0.31; 'steven': 0.31; 'allows': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'charset:us- ascii': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'nobody': 0.68; 'square': 0.74; 'received:50.22': 0.84 Date: Sat, 29 Jun 2013 14:42:58 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Closures in leu of pointers? In-Reply-To: <51cf332f$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <2a2072e3-4b12-4ada-872c-1240d2379928@googlegroups.com> <51CEE8E9.4070703@gmail.com> <51CF1309.1010504@rece.vub.ac.be> <51cf332f$0$29999$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: none X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372534884 news.xs4all.nl 15937 [2001:888:2000:d::a6]:35507 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49457 On 2013-06-29 19:19, Steven D'Aprano wrote: > Nobody ever asks why Python doesn't let you sort an int, or take > the square of a list... just to be ornery, you can sort an int: >>> i = 314159265 >>> ''.join(sorted(str(i))) '112345569' And I suppose, depending on how you define it, you can square a list: >>> lst = list('abcd') >>> import itertools >>> list(itertools.product(lst, lst)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('b', 'd'), ('c', 'a'), ('c', 'b'), ('c', 'c'), ('c', 'd'), ('d', 'a'), ('d', 'b'), ('d', 'c'), ('d', 'd')] Or, if you want to do it frequently, Python graciously even allows you to do things like >>> class MultiList(list): ... def __pow__(self, power): ... return list(itertools.product(*([self] * power))) ... >>> lst = MultiList("abcd") >>> lst ** 2 [('a', 'a'), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('b', 'd'), ('c', 'a'), ('c', 'b'), ('c', 'c'), ('c', 'd'), ('d', 'a'), ('d', 'b'), ('d', 'c'), ('d', 'd')] :-) -tkc