X-Received: by 10.224.175.65 with SMTP id w1mr7563878qaz.7.1360521914212; Sun, 10 Feb 2013 10:45:14 -0800 (PST) X-Received: by 10.49.60.40 with SMTP id e8mr783024qer.40.1360521914182; Sun, 10 Feb 2013 10:45:14 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!p13no7292440qai.0!news-out.google.com!k2ni23359qap.0!nntp.google.com!p13no8534636qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Sun, 10 Feb 2013 10:45:13 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.196.111.103; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj NNTP-Posting-Host: 70.196.111.103 References: <680e50a4-6569-49cf-b369-0be450545d50@googlegroups.com> <5115c455$0$6574$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <14880592-debf-42de-8756-e47e59aeb302@googlegroups.com> Subject: Re: LangWart: Method congestion from mutate multiplicty From: Rick Johnson Cc: python-list@python.org Injection-Date: Sun, 10 Feb 2013 18:45:14 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:38595 On Sunday, February 10, 2013 2:39:21 AM UTC-6, Terry Reedy wrote: > While it is true that sorted(iterable) is essentially > > def sorted(iterable): > tem = list(iterable) > tem.sort > return tem > > the body is not an expression and cannot be substituted in an > expression. Yes but the body can be compressed to this single line: "list(iterable).sort()" > Reversed(iterable) is more complicated because it returns an iterator, > not a list, and looks for a class-specific __reversed__ method. > [...] Well if you're taking the position that iterators are difficult to create i say you are exaggerating a bit. Using the for loop: py> for LOCALVAR in SEQUENCE: ... do_something we can get the iterator for free. If however you want to control the iteration /without/ being locked into a loop, you can explicitly call: py> iter(seq) Or, if you prefer methods over global functions: py> seq.__iter__() Or, if python employed /true/ OOP paradigm: py> Iterator(seq) > Even if list mutation methods returned the list, which they do not and > for good reason, I am not proposing that in-place modification return the object. > reversed(it) is not the same as list(it).reverse(). So > that part of the premise of this thread is wrong. Well, it's not the same /now/, because of how Python handles this operation. The status quo is to encourage the implicit idiom over the explicit, however, this behavior could be optimized to cleanly handle /explicit/ syntax only.