diff --git a/tests/test-highlight.t b/tests/test-highlight.t
--- a/tests/test-highlight.t
+++ b/tests/test-highlight.t
@@ -26,7 +26,7 @@ create random Python file to exercise Py
> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
> """
>
- > from itertools import dropwhile, ifilter, islice, count, chain
+ > import itertools
>
> def primes():
> """Generate all primes."""
@@ -35,12 +35,13 @@ create random Python file to exercise Py
> # It is important to yield *here* in order to stop the
> # infinite recursion.
> yield p
- > ns = ifilter(lambda n: n % p != 0, ns)
+ > ns = itertools.ifilter(lambda n: n % p != 0, ns)
> for n in sieve(ns):
> yield n
>
- > odds = ifilter(lambda i: i % 2 == 1, count())
- > return chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
+ > odds = itertools.ifilter(lambda i: i % 2 == 1, itertools.count())
+ > dropwhile = itertools.dropwhile
+ > return itertools.chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
>
> if __name__ == "__main__":
> import sys
@@ -49,7 +50,7 @@ create random Python file to exercise Py
> except (ValueError, IndexError):
> n = 10
> p = primes()
- > print("The first %d primes: %s" % (n, list(islice(p, n))))
+ > print("The first %d primes: %s" % (n, list(itertools.islice(p, n))))
> EOF
$ echo >> primes.py # to test html markup with an empty line just before EOF
$ hg ci -Ama
@@ -74,7 +75,7 @@ hgweb filerevision, html
-
- view primes.py @ 0:f4fca47b67e6
+ view primes.py @ 0:687f2d169546
draft default tip
@@ -159,7 +160,7 @@ hgweb filerevision, html
where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
"""
-
from itertools import dropwhile, ifilter, islice, count, chain
+
import itertools
def primes():
"""Generate all primes."""
@@ -168,22 +169,23 @@ hgweb filerevision, html
# It is important to yield *here* in order to stop the
# infinite recursion.
yield p
-
ns = ifilter(lambda n: n % p != 0, ns)
+
ns = itertools.ifilter(lambda n: n % p != 0, ns)
for n in sieve(ns):
yield n
-
odds = ifilter(lambda i: i % 2 == 1, count())
-
return chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
-
-
if __name__ == "__main__":
-
import sys
-
try:
-
n = int(sys.argv[1])
-
except (ValueError, IndexError):
-
n = 10
-
p = primes()
-
print("The first %d primes: %s" % (n, list(islice(p, n))))
-
+
odds = itertools.ifilter(lambda i: i % 2 == 1, itertools.count())
+
dropwhile = itertools.dropwhile
+
return itertools.chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
+
+
if __name__ == "__main__":
+
import sys
+
try:
+
n = int(sys.argv[1])
+
except (ValueError, IndexError):
+
n = 10
+
p = primes()
+
print("The first %d primes: %s" % (n, list(itertools.islice(p, n))))
+
@@ -251,7 +253,7 @@ hgweb fileannotate, html
- annotate primes.py @ 0:f4fca47b67e6
+ annotate primes.py @ 0:687f2d169546
draft default tip
@@ -318,19 +320,19 @@ hgweb fileannotate, html
-
+
0
|
1 """Fun with generators. Corresponding Haskell implementation: |
@@ -340,14 +342,14 @@ hgweb fileannotate, html
2 |
@@ -357,14 +359,14 @@ hgweb fileannotate, html
3 primes = 2 : sieve [3, 5..] |
@@ -374,14 +376,14 @@ hgweb fileannotate, html
4 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] |
@@ -391,14 +393,14 @@ hgweb fileannotate, html
5 """ |
@@ -408,14 +410,14 @@ hgweb fileannotate, html
6 |
@@ -425,31 +427,31 @@ hgweb fileannotate, html
- 7 from itertools import dropwhile, ifilter, islice, count, chain |
+ 7 import itertools |
|
8 |
@@ -459,14 +461,14 @@ hgweb fileannotate, html
9 def primes(): |
@@ -476,14 +478,14 @@ hgweb fileannotate, html
10 """Generate all primes.""" |
@@ -493,14 +495,14 @@ hgweb fileannotate, html
11 def sieve(ns): |
@@ -510,14 +512,14 @@ hgweb fileannotate, html
12 p = ns.next() |
@@ -527,14 +529,14 @@ hgweb fileannotate, html
13 # It is important to yield *here* in order to stop the |
@@ -544,14 +546,14 @@ hgweb fileannotate, html
14 # infinite recursion. |
@@ -561,14 +563,14 @@ hgweb fileannotate, html
15 yield p |
@@ -578,31 +580,31 @@ hgweb fileannotate, html
- 16 ns = ifilter(lambda n: n % p != 0, ns) |
+ 16 ns = itertools.ifilter(lambda n: n % p != 0, ns) |
|
17 for n in sieve(ns): |
@@ -612,14 +614,14 @@ hgweb fileannotate, html
18 yield n |
@@ -629,14 +631,14 @@ hgweb fileannotate, html
19 |
@@ -646,204 +648,221 @@ hgweb fileannotate, html
- 20 odds = ifilter(lambda i: i % 2 == 1, count()) |
+ 20 odds = itertools.ifilter(lambda i: i % 2 == 1, itertools.count()) |
|
- 21 return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) |
+ 21 dropwhile = itertools.dropwhile |
|
- 22 |
+ 22 return itertools.chain([2], sieve(dropwhile(lambda n: n < 3, odds))) |
|
- 23 if __name__ == "__main__": |
+ 23 |
|
- 24 import sys |
+ 24 if __name__ == "__main__": |
|
- 25 try: |
+ 25 import sys |
|
- 26 n = int(sys.argv[1]) |
+ 26 try: |
|
- 27 except (ValueError, IndexError): |
+ 27 n = int(sys.argv[1]) |
|
- 28 n = 10 |
+ 28 except (ValueError, IndexError): |
|
- 29 p = primes() |
+ 29 n = 10 |
|
- 30 print("The first %d primes: %s" % (n, list(islice(p, n)))) |
+ 30 p = primes() |
|
- 31 |
+ 31 print("The first %d primes: %s" % (n, list(itertools.islice(p, n)))) |
+
+
+
+
+
+ |
+ 32 |