This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steve21 LambertDW, rhettinger, steve21 2009-01-27.01:42:17 0.0030453282 No <1233020539.44.0.269039576151.issue5032@psf.upfronthosting.co.za>
Content
```Here's a couple of functions I use with count and step:

def cf_e():
'''return: (iterator) the infinite continued fraction for e
e=[2; 1, 2, 1, 1, 4, 1, 1, 6, 1 , ... , 1, 2k, 1, ...]
'''
yield 2
for k in itertools.count(2, 2):
yield 1
yield k
yield 1

def prime_factors(n):
'''n: (int > 1)
return: (list) the sorted list of tuples (p,e) of prime factors of n
p is a prime factor, e is the number of times the factor is used
'''
ret = []
if n <= 1:
return ret

# factors: use known (small) primes, then possible primes (odd numbers)
for factor in itertools.chain([2,3,5,7,11], itertools.count(13, 2)):
if factor*factor > n:
if n != 1:
ret += [(n, 1)]
break
for e in itertools.count(0):
div, mod = divmod(n, factor)
if mod != 0:
break
n = div
if e >= 1:
ret += [(factor, e)]
return ret```
History
Date User Action Args
2009-01-27 01:42:19steve21setrecipients: + steve21, rhettinger, LambertDW
2009-01-27 01:42:19steve21setmessageid: <1233020539.44.0.269039576151.issue5032@psf.upfronthosting.co.za>