Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.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.062 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.01; 'subject:would': 0.07; 'parameter': 0.09; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'itertools': 0.16; 'subject:key': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'import': 0.22; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'stuff': 0.32; 'subject:all': 0.32; 'could': 0.34; 'something': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'really': 0.36; 'false': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'how': 0.40; 'even': 0.60; 'chance': 0.65; '20,': 0.68; 'instantly': 0.84; 'subject:Idea': 0.84; 'instant': 0.97; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ra1zTyUtGQqFR5McSlTzA2P3J00fs88qI1qu/4rLSEc=; b=oFzPjg0Nh2LFnGdrVkZVnfwAbS9T9xj63wtl6m9EV568VE323pcWIwrFBqOCf4UIbK l8sCVh6Dv4Hc5L3B8YSM/B5GJyf/HkvZ0z26OFzjbRks57tlF36T6rp3N6/V1ZiMvim3 RXbyArrbwi12rVbnxRwuV4hxzNGRruh603UIgdA4nIonT13/hY8qpf+wok+tgBaXMQun 9khhSWQHLxIS7IIqYxEX6qAZaaiegjyUxUXPmA+iOSUSgQrRLQ6f8GZZd7MRwbFtr1iB PX68rR0u7RU8M1A6T20J+kJxpzQ5F3YN518RU54omAHrm92F8FnGMsCZEcehiUqHQgSv M/Qw== MIME-Version: 1.0 X-Received: by 10.220.182.193 with SMTP id cd1mr869951vcb.32.1371658829815; Wed, 19 Jun 2013 09:20:29 -0700 (PDT) In-Reply-To: <9150d9b7-e488-4f9f-beff-4a140bcc78f0@googlegroups.com> References: <9150d9b7-e488-4f9f-beff-4a140bcc78f0@googlegroups.com> Date: Thu, 20 Jun 2013 02:20:29 +1000 Subject: Re: Idea for key parameter in all() builting, would it be feasible? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371658839 news.xs4all.nl 15938 [2001:888:2000:d::a6]:55483 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48724 On Thu, Jun 20, 2013 at 2:14 AM, wrote: > And the following, although the same thing really as all(xrange(10**9)), is not as instant and will take even longer than the above. > >>>> all(map(lambda x: bool(x), xrange(10**9))) > > However if all by some chance (I don't know how this stuff works underneath) has a key parameter then we could do something like. > >>>> all(xrange(10**9), key=lambda x: bool(x)) > > Which would return False instantly (ideally). All you need is the iterator version of map(). In Python 3, that's the normal map(); in Python 2, use this: >>> from itertools import imap >>> all(imap(lambda x: bool(x), xrange(10**9))) False It's roughly instant, like you would expect. ChrisA