Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'elements.': 0.07; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'count,': 0.16; 'itertools': 0.16; 'lambda': 0.16; 'subject:generator': 0.16; 'true:': 0.16; 'import': 0.22; 'cc:addr:python.org': 0.22; 'fine': 0.24; 'cc:2**0': 0.24; 'header :In-Reply-To:1': 0.27; 'correct': 0.29; 'message- id:@mail.gmail.com': 0.30; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'yield': 0.36; 'thanks': 0.36; 'should': 0.36; 'clear': 0.37; 'thank': 0.38; 'filter': 0.38; 'changed': 0.39; 'number,': 0.60; 'break': 0.61; 'more': 0.64; 'to:addr:gmail.com': 0.65 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 :cc:content-type; bh=9PLjl/GFqAs7KuNl/EZVXGAGcmrhr6FSv/fvJZqusSU=; b=MpFRmZB6Pr9fXSORXcWf7AR7GUZCy6GwK9wof09NYK9ShAlTAE1Vpr02IFGIXbQe49 tMKcXT0m0054aBFgUIUI5j+nBbHOyFZgJ173rP0O8dYbtEcw0eEOu36z4koqKiAeUE96 Gp7FVmmS0Af94sk/KUyZjA0NveyP5mRW4PCx0u9DDnyIK/s1lHBoYUsYP49OTuupzPEp FsaNPZmagj13+1dxgauoKrp5KDpRk8k83rLWpY2zgAgT3MoBJV0+Lt3qfrRBct8vsD8Z zCNux7Bgdgl+82iz/+EUQ0zPjiHqf+FNlS4rNfmSAWsZmGeBj56usuuhcvxsLK0iYuJ9 zLkg== MIME-Version: 1.0 X-Received: by 10.58.119.161 with SMTP id kv1mr562432veb.21.1391338120803; Sun, 02 Feb 2014 02:48:40 -0800 (PST) In-Reply-To: <8118b17c-3352-4832-8567-089bd14c21ce@googlegroups.com> References: <8118b17c-3352-4832-8567-089bd14c21ce@googlegroups.com> Date: Sun, 2 Feb 2014 10:48:40 +0000 Subject: Re: generator slides review From: andrea crotti To: Miki Tebeka Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391338128 news.xs4all.nl 2934 [2001:888:2000:d::a6]:55483 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65257 2014-02-01 Miki Tebeka : > > My 2 cents: > > slide 4: > [i*2 for i in range(10)] > Well this is not correct in theory because the end should be the max number, not the number of elements. So it should be [i*2 for i in range(10/2)] which might be fine but it's not really more clear imho.. > slide 9: > while True: > try: > it = next(g) > body(it) > except StopIteration: > break > Changed it thanks > slide 21: > from itertools import count, ifilterfalse > > def divided_by(p): > return lambda n: n % p == 0 > > def primes(): > nums = count(2) > while True: > p = next(nums) > yield p > nums = ifilterfalse(divided_by(p), nums) > Thank you that's nicer, but ifiilterfalse is not in Python 3 (could use filter of course).