Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65257

Re: generator slides review

References <mailman.6278.1391263956.18130.python-list@python.org> <8118b17c-3352-4832-8567-089bd14c21ce@googlegroups.com>
Date 2014-02-02 10:48 +0000
Subject Re: generator slides review
From andrea crotti <andrea.crotti.0@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6302.1391338128.18130.python-list@python.org> (permalink)

Show all headers | View raw


2014-02-01 Miki Tebeka <miki.tebeka@gmail.com>:
>
> 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).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-01 14:12 +0000
  Re: generator slides review Miki Tebeka <miki.tebeka@gmail.com> - 2014-02-01 08:50 -0800
    Re: generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-02 10:48 +0000
      Re: generator slides review Miki Tebeka <miki.tebeka@gmail.com> - 2014-02-02 06:59 -0800
        Re: generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-02 22:55 +0000
    Re: generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-02 10:50 +0000
    Re: generator slides review andrea crotti <andrea.crotti.0@gmail.com> - 2014-02-02 10:52 +0000
    Re: generator slides review Peter Otten <__peter__@web.de> - 2014-02-02 13:47 +0100

csiph-web